Skip to content

Commit

Permalink
chore: prod yml ci/cd를 blue & green 으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
fromitive committed Oct 24, 2024
1 parent f5ac548 commit ae02661
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions .github/workflows/backend-prod-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,29 @@ jobs:
docker tag ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }} ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker push ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
deploy-a:
needs: build-and-test
runs-on: prod-a

deploy-new-container:
needs: build-and-test
strategy:
matrix:
runner: [prod-a, prod-b]
runs-on: [ self-hosted, ${{ matrix.runner }} ]
steps:
- name: Pull Image And Restart Container on Production A
run: |
docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }}
docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker image prune -a -f
docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
- name: Checkout repository
uses: actions/checkout@v4

deploy-b:
needs: deploy-a
runs-on: prod-b
- name: Deploy new container on ${{ matrix.runner }}
run: |
bash launch_next_container.sh ${GITHUB_SHA::7} prod ${{ secrets.BE_DOCKERHUB_USERNAME }} ${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}
working-directory: backend/deploy

switch-new-container:
needs: deploy-new-container
strategy:
matrix:
runner: [prod-a, prod-b]
runs-on: [ self-hosted, ${{ matrix.runner }} ]
steps:
- name: Pull Image And Restart Container on Production B
- name: Switch from old to new container on ${{ matrix.runner }}
run: |
docker login -u ${{ secrets.BE_DOCKERHUB_USERNAME }} -p ${{ secrets.BE_DOCKERHUB_PASSWORD }}
docker stop ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker rm ${{ secrets.BE_DOCKER_CONTAINER_NAME }} | true
docker image prune -a -f
docker pull ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
docker run --name ${{ secrets.BE_DOCKER_CONTAINER_NAME }} -d -v /logs:/logs -p 80:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.BE_DOCKERHUB_USERNAME }}/${{ secrets.BE_DOCKER_IMAGE_NAME_PROD }}:${GITHUB_SHA::7}
bash switch_blue_green_container.sh
working-directory: backend/deploy

0 comments on commit ae02661

Please sign in to comment.