Skip to content

BE CD for Prod

BE CD for Prod #62

Workflow file for this run

name: BE CD for Prod
on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- backend/**
env:
ARTIFACT_NAME: app-artifact
JAR_NAME: app.jar
APP_PATH: ~/app
jobs:
build:
uses: ./.github/workflows/build.yml
with:
profile: prod
secrets:
secret_yml: ${{ secrets.PROD_SECRET_YML }}
deploy-a:
needs: [ build ]
uses: ./.github/workflows/self-hosted-runner-deployment.yml
with:
self_hosted_runner: prod-c # todo a
artifact_name: ${{ needs.build.outputs.artifact_name }}
jar_name: ${{ needs.build.outputs.jar_name }}
profile: prod
app_path: ~/app
deploy-b:
needs: [ build ]
uses: ./.github/workflows/self-hosted-runner-deployment.yml
with:
self_hosted_runner: prod-d # todo b
artifact_name: ${{ needs.build.outputs.artifact_name }}
jar_name: ${{ needs.build.outputs.jar_name }}
profile: prod
app_path: ~/app
deploy-rollback-call:
needs: [ deploy-a, deploy-b ]
if: contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
steps:
- name: Send notification to Discord # todo
run: echo "테스트입니다"
# deploy-rollback-call:
# needs: [ deploy-a, deploy-b ]
# runs-on: [ prod-c, prod-d ] # todo a, b
# if: ${{ needs.deploy-a.result == 'failure' || needs.deploy-b.result == 'failure' }}
# steps:
# - name: Rollback a
# if: runner.name == 'prod-c'
# uses: ./.github/actions/rollback/action.yml
# with:
# port: ${{ needs.deploy-a.outputs.green_port }}
# - name: Rollback b
# if: ${{ needs.deploy-b.result == 'failure'}}
# uses: ./.github/actions/rollback/action.yml
# with:
# port: ${{ needs.deploy-b.outputs.green_port }}
rollback-a:
needs: [ deploy-rollback-call, deploy-a ]
runs-on: prod-c
steps:
- name: Rollback a
run: |
echo "Deploy failed. Rollback server port: ${{ needs.deploy-a.outputs.green_port }}"
sudo lsof -t -i :${{ needs.deploy-a.outputs.green_port }} | xargs kill -9
exit 1
rollback-b:
needs: [ deploy-rollback-call, deploy-b ]
runs-on: prod-d
steps:
- name: Rollback b
run: |
echo "Deploy failed. Rollback server port: ${{ needs.deploy-b.outputs.green_port }}"
sudo lsof -t -i :${{ needs.deploy-b.outputs.green_port }} | xargs kill -9
exit 1
nginx-config: # 여기서 시작
needs: [ deploy-a, deploy-b ]
if: success()
runs-on: [ prod ]
steps:
- name: Change Nginx Config
run: |
${{ env.APP_PATH }}/change_nginx_port_forwarding.sh ${{ needs.deploy.outputs.green_port }}
- name: Rollback
if: ${{ failure() }}
run: |
echo "Nginx Config Change failed"
echo "Rollback Nginx Config and Green deployment"
${{ env.APP_PATH }}/change_nginx_port_forwarding.sh ${{ needs.deploy.outputs.blue_port }}
sudo lsof -i :${{ needs.deploy.outputs.green_port }} | awk 'NR!=1 {print $2}' | xargs kill -9
exit 1
blue-down:
needs: [ nginx-config ]
runs-on: [ prod ]
steps:
- name: Blue Down
run: |
sudo kill -15 $(sudo lsof -t -i: ${{ needs.deploy.outputs.blue_port }})
echo "Blue Down completed"
on-failure:
needs: [ blue-down ] # 알림
runs-on: [ prod ]
if: ${{ needs.blue-down.result == 'failure' }}
steps:
- name: Send Notification
run: echo "테스트입니다"