Skip to content

Commit 27c845c

Browse files
committed
chore: rename build-and-deploy job to build-image, streamline Docker build process for frontend and backend, and add deploy job for SSH-based deployment
1 parent d778acb commit 27c845c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: pnpm run lint
4848
working-directory: ./frontend
4949

50-
build-and-deploy:
50+
build-image:
5151
runs-on: ubuntu-latest
5252
needs: lint
5353
if: github.ref == 'refs/heads/main'
@@ -56,9 +56,6 @@ jobs:
5656
- name: Checkout repository
5757
uses: actions/checkout@v4
5858

59-
- name: Set up QEMU
60-
uses: docker/setup-qemu-action@v2
61-
6259
- name: Set up Docker Buildx
6360
uses: docker/setup-buildx-action@v2
6461

@@ -75,7 +72,7 @@ jobs:
7572
context: ./frontend
7673
file: ./frontend/Dockerfile
7774
push: true
78-
platforms: linux/amd64,linux/arm64
75+
platforms: linux/amd64
7976
tags: |
8077
ghcr.io/nctucsunion/pastexam:frontend
8178
ghcr.io/nctucsunion/pastexam:frontend-${{ github.sha }}
@@ -90,9 +87,29 @@ jobs:
9087
context: ./backend
9188
file: ./backend/Dockerfile
9289
push: true
93-
platforms: linux/amd64,linux/arm64
90+
platforms: linux/amd64
9491
tags: |
9592
ghcr.io/nctucsunion/pastexam:backend
9693
ghcr.io/nctucsunion/pastexam:backend-${{ github.sha }}
9794
cache-from: type=registry,ref=ghcr.io/nctucsunion/pastexam:backend-buildcache
9895
cache-to: type=registry,ref=ghcr.io/nctucsunion/pastexam:backend-buildcache,mode=max
96+
97+
deploy:
98+
runs-on: ubuntu-latest
99+
needs: build-image
100+
if: github.ref == 'refs/heads/main'
101+
102+
steps:
103+
- name: Deploy via SSH
104+
uses: appleboy/ssh-action@v1.0.3
105+
with:
106+
host: ${{ secrets.DEPLOY_HOST }}
107+
username: ${{ secrets.DEPLOY_USER }}
108+
key: ${{ secrets.DEPLOY_KEY }}
109+
script: |
110+
cd ${{ secrets.DEPLOY_DIRECTORY }}
111+
if [ -n "${{ secrets.GHCR_TOKEN }}" ]; then
112+
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
113+
fi
114+
docker compose pull
115+
docker compose up -d

0 commit comments

Comments
 (0)