Skip to content

Commit

Permalink
Fixed deploy (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1ckyf0x committed Jul 21, 2024
1 parent 8f67948 commit 70e68f4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
75 changes: 55 additions & 20 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,75 @@ on:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
deploy:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/gpont/watch_together:latest
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Deploy to VPS
uses: appleboy/ssh-action@master
deploy:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: Checkout docker-compose.yml
uses: actions/checkout@v4
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_SSH_USERNAME }}
password: ${{ secrets.VPS_SSH_PASSWORD }}
script: |
docker run -d --name watch_together \
-e BOT_TOKEN=${{ secrets.BOT_TOKEN }} \
-p 3000:3000 watch_together:latest
sparse-checkout: |
docker-compose.yml
sparse-checkout-cone-mode: false

- name: Pull Docker image from GitHub Container Registry
- name: Generate .env file
run: |
docker pull ghcr.io/gpont/watch_together:latest
docker tag ghcr.io/gpont/watch_together:latest watch_together:latest
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" >> .env
- name: Copy files to VPS
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
port: ${{ secrets.DEPLOY_PORT }}
key: ${{ secrets.DEPLOY_KEY }}
source: "./docker-compose.yml,./.env"
target: "~/docker-services/watch_together/"

- name: Deploy to VPS
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
port: ${{ secrets.DEPLOY_PORT }}
key: ${{ secrets.DEPLOY_KEY }}
script: |
cd docker-services/watch_together
docker compose pull
docker compose down
docker compose up -d

0 comments on commit 70e68f4

Please sign in to comment.