Skip to content

Commit

Permalink
chore: prod v2 롤백 작업 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-byeol committed Nov 29, 2024
1 parent 6fb4d09 commit 468ff1f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/backend-cd-prod-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:

env:
DOCKERHUB_REPOSITORY: ody-official
DOCKER_CONTAINER_NAME: ody-prod-app

jobs:
build-and-push:
Expand Down Expand Up @@ -69,6 +68,13 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Back Up Image For Rollback
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest || true
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous || true
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous || true
- name: Docker Image Build And Push
run: docker build --platform linux/arm64 -t ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:${{ github.sha }}-prod_v2 -f Dockerfile . --push

Expand All @@ -93,8 +99,31 @@ jobs:
export DOCKERHUB_REPOSITORY=$DOCKERHUB_REPOSITORY
export PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}
export JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_PASSWORD }}
export GIT_SHA=${{ github.sha }}
export TAG=${{ github.sha }}-prod_v2
docker compose up -d
#TODO: 도메인 연결 시, health check 필요

- name: Rollback if Health Check fails
if: failure()
run: |
docker compose down || true
docker rmi $(docker images -q) -f || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
export DOCKERHUB_REPOSITORY=$DOCKERHUB_REPOSITORY
export PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}
export JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_PASSWORD }}
export TAG=prod-previous
docker compose up -d
- name: Tag successful deployment as latest
if: success()
run: |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:${{ github.sha }}-prod_v2 ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest
- name: Check Docker Process
if: always()
run: docker ps

0 comments on commit 468ff1f

Please sign in to comment.