Skip to content

BE CD for Prod

BE CD for Prod #66

Workflow file for this run

name: BE CD for Prod
on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- backend/**
env:
APP_PATH: ~/app
PROFILE: prod
jobs:
build:
uses: ./.github/workflows/build.yml
with:
profile: prod
secrets:
secret_yml: ${{ secrets.PROD_SECRET_YML }}
deploy-a:
needs: [ build ]
runs-on: [ prod-c ] # todo a
outputs:
blue_port: ${{ steps.blue-green.outputs.blue_port }}
green_port: ${{ steps.blue-green.outputs.green_port }}
steps:
- name: Deploy blue/green in A
id: blue-green
uses: ./.github/actions/blue-green/action.yml
with:
artifact_name: ${{ needs.build.outputs.artifact_name }}
jar_name: ${{ needs.build.outputs.jar_name }}
profile: ${{ env.PROFILE }}
app_path: ${{ env.APP_PATH }}
deploy-b:
needs: [ build ]
runs-on: [ prod-d ] # todo b
outputs:
blue_port: ${{ steps.blue-green.outputs.blue_port }}
green_port: ${{ steps.blue-green.outputs.green_port }}
steps:
- name: Deploy blue/green in B
id: blue-green
uses: ./.github/actions/blue-green/action.yml
with:
artifact_name: ${{ needs.build.outputs.artifact_name }}
jar_name: ${{ needs.build.outputs.jar_name }}
profile: ${{ env.PROFILE }}
app_path: ${{ env.APP_PATH }}
deploy-rollback-notification:
needs: [ deploy-a, deploy-b ]
if: failure() && contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
outputs:
green_port_a: ${{ needs.deploy-a.outputs.green_port }}
green_port_b: ${{ needs.deploy-b.outputs.green_port }}
steps:
- name: Send notification to Discord # todo
run: echo "테스트입니다"
rollback-a:
needs: [ deploy-rollback-notification ]
if: failure() && contains(needs.*.result, 'success')
runs-on: [ prod-c ] # todo a
steps:
- name: Shutdown green in A
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.deploy-rollback-notification.outputs.green_port_a }}
rollback-b:
needs: [ deploy-rollback-notification ]
if: failure() && contains(needs.*.result, 'success')
runs-on: [ prod-d ] # todo b
steps:
- name: Shutdown green in B
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.deploy-rollback-notification.outputs.green_port_b }}
configure-nginx-a:
needs: [ deploy-a ]
runs-on: [ prod-c ] # todo a
outputs:
blue_port: ${{ needs.deploy-a.outputs.blue_port }}
green_port: ${{ needs.deploy-a.outputs.green_port }}
steps:
- name: Change Nginx port forwarding to green port in A
uses: ./.github/actions/nginx-port-forwarding/action.yml
with:
app_path: ${{ env.APP_PATH }}
new_port: ${{ needs.deploy-a.outputs.green_port }}
- name: Reload Nginx
run: sudo nginx -s reload # todo 에러 처리
configure-nginx-b:
needs: [ deploy-b ]
runs-on: [ prod-d ] # todo b
outputs:
blue_port: ${{ needs.deploy-b.outputs.blue_port }}
green_port: ${{ needs.deploy-b.outputs.green_port }}
steps:
- name: Update Nginx port forwarding to green port in B
uses: ./.github/actions/nginx-port-forwarding/action.yml
with:
app_path: ${{ env.APP_PATH }}
new_port: ${{ needs.deploy-b.outputs.green_port }}
- name: Reload Nginx
run: sudo nginx -s reload # todo 에러 처리
configure-nginx-rollback-notification:
needs: [ configure-nginx-a, configure-nginx-b ]
if: failure() && contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
outputs:
blue_port_a: ${{ needs.configure-nginx-a.outputs.blue_port }}
green_port_a: ${{ needs.configure-nginx-a.outputs.green_port }}
blue_port_b: ${{ needs.configure-nginx-b.outputs.blue_port }}
green_port_b: ${{ needs.configure-nginx-b.outputs.green_port }}
steps:
- name: Send notification to Discord # todo
run: echo "테스트입니다"
rollback-nginx-a:
needs: [ configure-nginx-rollback-notification ]
if: failure() && contains(needs.*.result, 'success')
runs-on: [ prod-c ] # todo a
steps:
- name: Rollback Nginx port forwarding to blue port in A
uses: ./.github/actions/nginx-port-forwarding/action.yml
with:
app_path: ${{ env.APP_PATH }}
new_port: ${{ needs.configure-nginx-rollback-notification.outputs.blue_port_a }}
- name: Reload Nginx
run: sudo nginx -s reload # todo 에러 처리
- name: Shutdown green in A
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.configure-nginx-rollback-notification.outputs.green_port_a }}
rollback-nginx-b:
needs: [ configure-nginx-rollback-notification ]
if: failure() && contains(needs.*.result, 'success')
runs-on: [ prod-d ] # todo b
steps:
- name: Rollback Nginx port forwarding to blue port in B
uses: ./.github/actions/nginx-port-forwarding/action.yml
with:
app_path: ${{ env.APP_PATH }}
new_port: ${{ needs.configure-nginx-rollback-notification.outputs.blue_port_b }}
- name: Reload Nginx
run: sudo nginx -s reload # todo 에러 처리
- name: Shutdown green in B
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.configure-nginx-rollback-notification.outputs.green_port_b }}
blue-shutdown-a:
needs: [ configure-nginx-a ]
runs-on: [ prod-c ] # todo a
steps:
- name: Shutdown blue in A
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.configure-nginx-a.outputs.blue_port }}
blue-shutdown-b:
needs: [ configure-nginx-b ]
runs-on: [ prod-d ] # todo b
steps:
- name: Shutdown blue in B
uses: ./.github/actions/shutdown/action.yml
with:
port: ${{ needs.configure-nginx-b.outputs.blue_port }}
# on-failure:
# needs: [ blue-down ] # 알림
# if: ${{ needs.blue-down.result == 'failure' }}
# steps:
# - name: Send Notification
# run: echo "테스트입니다"