From ae026612b4a0f42668e046753b0b48becdb5bb3b Mon Sep 17 00:00:00 2001 From: fromitive Date: Fri, 25 Oct 2024 00:28:33 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20prod=20yml=20ci/cd=EB=A5=BC=20blue=20&?= =?UTF-8?q?=20green=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-ci-cd.yml | 43 ++++++++++++------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/backend-prod-ci-cd.yml b/.github/workflows/backend-prod-ci-cd.yml index 10f6faacb..83b353135 100644 --- a/.github/workflows/backend-prod-ci-cd.yml +++ b/.github/workflows/backend-prod-ci-cd.yml @@ -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 \ No newline at end of file