prisma migrate step 추가 #16
This file contains hidden or 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
name: backend-dev | |
on: | |
push: | |
branches: ['chore/cicd'] | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push (latest tag only) | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/modern-agile-team/quizz-game-io-backend:latest | |
deploy: | |
needs: build-and-push | |
runs-on: [self-hosted, homelab] | |
permissions: | |
contents: read | |
packages: read | |
steps: | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run Prisma migrate before starting app # 변경점: 빌드된 latest 이미지를 활용해 migrate 실행 | |
run: | | |
docker run --rm \ | |
--network quizzes_game_io_backend_default \ | |
--env-file /home/github-runner/app/.env \ | |
ghcr.io/modern-agile-team/quizz-game-io-backend:latest \ | |
npx prisma migrate deploy | |
- name: Update app container only | |
env: | |
IMAGE: ghcr.io/modern-agile-team/quizz-game-io-backend:latest | |
NAME: quizzes_game_io_backend_app | |
ENV_FILE: /home/github-runner/app/.env | |
run: | | |
docker pull "$IMAGE" | |
docker rm -f "$NAME" || true | |
docker run -d \ | |
--name quizzes_game_io_backend_app \ | |
--restart unless-stopped \ | |
--env-file /home/github-runner/app/.env \ | |
--network quizzes_game_io_backend_default \ | |
-p 127.0.0.1:8080:8080 \ | |
"$IMAGE" |