BE CD for Prod #65
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-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') | |
uses: ./.github/workflows/server-rollback.yml | |
with: | |
self_hosted_runner: prod-c # todo a | |
port: ${{ needs.deploy-rollback-notification.outputs.green_port_a }} | |
rollback-b: | |
needs: [ deploy-rollback-notification ] | |
if: failure() && contains(needs.*.result, 'success') | |
uses: ./.github/workflows/server-rollback.yml | |
with: | |
self_hosted_runner: prod-d # todo b | |
port: ${{ needs.deploy-rollback-notification.outputs.green_port_b }} | |
nginx-config: # 여기서 시작 | |
needs: [ deploy-a, deploy-b ] | |
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 "테스트입니다" |