Split build-on-server and registry deploy workflows

This commit is contained in:
Lectom C Han
2026-02-04 14:54:43 +09:00
parent c5c3e30e78
commit 02f40e9cc3
2 changed files with 78 additions and 43 deletions

View File

@@ -0,0 +1,54 @@
name: Deploy (registry)
on:
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ vars.HARBOR_ENDPOINT }}
username: ${{ vars.HARBOR_ROBOT_ACCOUNT }}
password: ${{ secrets.HARBOR_ROBOT_KEY }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ vars.HARBOR_ENDPOINT }}/${{ vars.IMAGE_NAME }}:latest
${{ vars.HARBOR_ENDPOINT }}/${{ vars.IMAGE_NAME }}:${{ github.sha }}
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ vars.SSH_HOST }}
username: ${{ vars.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ vars.SSH_PORT }}
script: |
cd ${{ secrets.DEPLOY_PATH }}
cat << 'ENVEOF' > .env
${{ secrets.DEPLOY_ENV_FILE }}
ENVEOF
# Export variables from .env file
set -a
source .env
set +a
docker compose --env-file .env pull
docker compose --env-file .env up -d

View File

@@ -1,56 +1,37 @@
name: Deploy (main) name: Deploy (build on server)
on: on:
push: push:
branches: ["main"] branches: [ "main" ]
workflow_dispatch: workflow_dispatch:
jobs: jobs:
build-and-deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
steps: steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.REGISTRY }}/${{ secrets.IMAGE_NAME }}:latest
${{ secrets.REGISTRY }}/${{ secrets.IMAGE_NAME }}:${{ github.sha }}
- name: Deploy via SSH - name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
with: with:
host: ${{ secrets.SSH_HOST }} host: ${{ vars.SSH_HOST }}
username: ${{ secrets.SSH_USER }} username: ${{ vars.SSH_USER }}
key: ${{ secrets.SSH_KEY }} key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }} port: ${{ vars.SSH_PORT }}
script: | script: |
cd ${{ secrets.DEPLOY_PATH }} cd ${{ secrets.DEPLOY_PATH }}
cat << 'EOF' > .env cat << 'ENVEOF' > .env
${{ secrets.DEPLOY_ENV_FILE }} ${{ secrets.DEPLOY_ENV_FILE }}
EOF ENVEOF
# Export variables from .env file # Export variables from .env file
set -a set -a
source .env source .env
set +a set +a
docker compose --env-file .env pull git fetch origin main
docker compose --env-file .env up -d git checkout main
git pull --ff-only
docker compose --env-file .env up -d --build