-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (112 loc) · 4.52 KB
/
develop_cd.yml
File metadata and controls
127 lines (112 loc) · 4.52 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: develop(cd)
on:
workflow_dispatch:
inputs:
version:
description: 'commit_hash'
required: true
jobs:
cd:
runs-on: ubuntu-latest
environment: DEVELOP
steps:
- name: checkout
uses: actions/checkout@master
- name: create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: root
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: mkdir -p ~/TodaysFail-Backend
- name: copy source via ssh key
uses: burnett01/rsync-deployments@4.1
with:
switches: -avzr
remote_path: ~/TodaysFail-Backend
remote_host: ${{ secrets.HOST }}
remote_port: ${{ secrets.PORT }}
remote_user: root
remote_key: ${{ secrets.KEY }}
- name: connect ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: root
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REGISTRY_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
cd ~/TodaysFail-Backend
VERSION=${{ github.event.inputs.version }}
sed -i "s/VERSION=.*/VERSION=$VERSION/" .env
EXIST_BLUE=$(docker-compose -f ~/TodaysFail-Backend/docker-compose-blue.yml ps | grep todaysfail-blue | awk '{print $1}')
if [ -z "${EXIST_BLUE}" ]
then
# GREEN이 실행중인 경우
START_CONTAINER=blue
START_PORT=8080
STOP_CONTAINER=green
STOP_PORT=8081
sed -i "s/API_SERVER_PORT=.*/API_SERVER_PORT=8080/" .env
else
# BLUE가 실행중인 경우
START_CONTAINER=green
START_PORT=8081
STOP_CONTAINER=blue
STOP_PORT=8080
sed -i "s/API_SERVER_PORT=.*/API_SERVER_PORT=8081/" .env
fi
docker-compose -f ~/TodaysFail-Backend/docker-compose-$START_CONTAINER.yml pull
docker-compose -f ~/TodaysFail-Backend/docker-compose-$START_CONTAINER.yml up --build -d
docker system prune --all -f
for cnt in {1..10}
do
DEPLOY_STATUS=$(curl -s http://localhost:$START_PORT/api/v1/examples/health | grep \"status\":200)
if [ -z "${DEPLOY_STATUS}" ]
then
echo "Deploying..."
else
break
fi
sleep 5
done
if [ $cnt -eq 10 ]
then
echo "Deploy Failed"
exit 1
fi
sed -i "s/$STOP_PORT/$START_PORT/" ~/../etc/nginx/conf.d/service_url.inc
service nginx reload
docker-compose -f ~/TodaysFail-Backend/docker-compose-$STOP_CONTAINER.yml down
- name: Notify on success
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_USERNAME: '오늘의 실패'
SLACK_ICON: https://avatars.slack-edge.com/2023-07-26/5653063434977_51d6e36ad6977fe04337_192.png
SLACK_COLOR: '#008000'
SLACK_MESSAGE: |
*[DEV] 수동 배포 성공 🎉*
*배포 버전*
${{ github.event.inputs.version }}
*배포 내역 보기*
https://github.com/TodaysFail/TodaysFail-Backend/commit/${{ github.event.inputs.version }}
- name: Notify on failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_USERNAME: '오늘의 실패'
SLACK_ICON: https://avatars.slack-edge.com/2023-07-26/5653063434977_51d6e36ad6977fe04337_192.png
SLACK_COLOR: '#FF0000'
SLACK_MESSAGE: |
*[DEV] 수동 배포 실패 😥*
*배포 버전*
${{ github.event.inputs.version }}
*배포 내역 보기*
https://github.com/TodaysFail/TodaysFail-Backend/commit/${{ github.event.inputs.version }}