Skip to content

Commit a69a1d0

Browse files
committed
워크플로우 재작성
1 parent 396d16c commit a69a1d0

1 file changed

Lines changed: 11 additions & 67 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 11 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Blue-Green Deploy
22

33
on:
44
push:
5-
branches: [dev, refactor/#105_tempo_alloy]
5+
branches: [dev, feat/#107/re_deploy]
66

77
jobs:
88
build:
@@ -43,78 +43,22 @@ jobs:
4343
deploy:
4444
needs: build
4545
runs-on: ubuntu-latest
46+
4647
steps:
47-
- name: Deploy target container
48+
- name: Deploy
4849
uses: appleboy/ssh-action@v1.0.3
4950
with:
5051
host: ${{ secrets.EC2_HOST }}
5152
username: ${{ secrets.EC2_USERNAME }}
5253
key: ${{ secrets.EC2_SSH_KEY }}
5354
script: |
54-
CONF=/etc/nginx/conf.d/service-url.inc
55-
CURRENT_PORT=$(grep -oP '127.0.0.1:\K[0-9]+' $CONF || echo "8081")
56-
57-
if [ "$CURRENT_PORT" = "8080" ]; then
58-
TARGET=green
59-
else
60-
TARGET=blue
61-
fi
62-
55+
export DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/comfit-backend:${{ github.sha }}
56+
6357
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
64-
docker pull ${{ secrets.DOCKER_USERNAME }}/comfit-backend:${{ github.sha }}
65-
DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/comfit-backend:${{ github.sha }} docker-compose -f docker-compose-$TARGET.yml up -d
66-
67-
- name: Health check
68-
uses: appleboy/ssh-action@v1.0.3
69-
with:
70-
host: ${{ secrets.EC2_HOST }}
71-
username: ${{ secrets.EC2_USERNAME }}
72-
key: ${{ secrets.EC2_SSH_KEY }}
73-
script: |
74-
CONF=/etc/nginx/conf.d/service-url.inc
75-
CURRENT_PORT=$(grep -oP '127.0.0.1:\K[0-9]+' $CONF || echo "8081")
76-
77-
if [ "$CURRENT_PORT" = "8080" ]; then
78-
TARGET_PORT=8081
79-
else
80-
TARGET_PORT=8080
81-
fi
82-
83-
for i in {1..15}; do
84-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:$TARGET_PORT/actuator/health)
85-
echo "Attempt $i: HTTP $STATUS"
86-
if [ "$STATUS" = "200" ]; then
87-
exit 0
88-
fi
89-
sleep 5
90-
done
91-
exit 1
92-
93-
- name: Switch traffic
94-
uses: appleboy/ssh-action@v1.0.3
95-
with:
96-
host: ${{ secrets.EC2_HOST }}
97-
username: ${{ secrets.EC2_USERNAME }}
98-
key: ${{ secrets.EC2_SSH_KEY }}
99-
script: |
100-
/home/ubuntu/switch.sh
101-
102-
- name: Stop old container
103-
if: success()
104-
uses: appleboy/ssh-action@v1.0.3
105-
with:
106-
host: ${{ secrets.EC2_HOST }}
107-
username: ${{ secrets.EC2_USERNAME }}
108-
key: ${{ secrets.EC2_SSH_KEY }}
109-
script: |
110-
CONF=/etc/nginx/conf.d/service-url.inc
111-
CURRENT_PORT=$(grep -oP '127.0.0.1:\K[0-9]+' $CONF)
112-
113-
if [ "$CURRENT_PORT" = "8080" ]; then
114-
OLD=green
115-
else
116-
OLD=blue
117-
fi
118-
119-
docker-compose -f docker-compose-$OLD.yml down || true
58+
59+
docker pull $DOCKER_IMAGE
60+
61+
docker-compose down
62+
docker-compose up -d
63+
12064
docker image prune -f

0 commit comments

Comments
 (0)