-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |