-
Notifications
You must be signed in to change notification settings - Fork 2
103 lines (90 loc) · 2.94 KB
/
be-cd-prod.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 "테스트입니다"