Skip to content

Commit b33c9a9

Browse files
authored
Merge pull request #142 from umc-commit/fix/141-nginx-link
[FIX] nginx 설정파일 변경
2 parents 8d51a3e + 265f7a8 commit b33c9a9

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

.github/workflows/cd.yml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,27 @@ jobs:
3535

3636
- name: Deploy with Blue-Green
3737
run: |
38-
ssh ec2 <<'EOF'
38+
ssh ec2 "DOCKER_HUB_USERNAME=${{ secrets.DOCKER_HUB_USERNAME }} bash -s" <<'EOF'
39+
3940
echo "📦 Pulling latest image..."
40-
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/commit-api:latest
41+
docker pull $DOCKER_HUB_USERNAME/commit-api:latest
4142
4243
echo "🔍 Checking current active environment..."
43-
CURRENT=$(readlink -f /opt/app/nginx/default.conf)
44-
if echo "$CURRENT" | grep -q "default-blue.conf"; then
44+
if docker exec nginx-proxy test -f /etc/nginx/conf.d/default.conf; then
45+
CURRENT=$(docker exec nginx-proxy readlink -f /etc/nginx/conf.d/default.conf | xargs basename)
46+
else
47+
echo "❌ Cannot determine current config. Exiting."
48+
exit 1
49+
fi
50+
51+
if echo "$CURRENT" | grep -q "blue"; then
4552
TARGET_COLOR=green
4653
TARGET_PORT=3001
47-
TARGET_CONF=/opt/app/nginx/default-green.conf
54+
TARGET_CONF=/etc/nginx/conf.d/default-green.conf.disabled
4855
else
4956
TARGET_COLOR=blue
5057
TARGET_PORT=3000
51-
TARGET_CONF=/opt/app/nginx/default-blue.conf
58+
TARGET_CONF=/etc/nginx/conf.d/default-blue.conf.disabled
5259
fi
5360
5461
echo "🚀 Deploying to $TARGET_COLOR container on port $TARGET_PORT..."
@@ -60,27 +67,22 @@ jobs:
6067
-p $TARGET_PORT:3000 \
6168
--network=commit-networks \
6269
-v /opt/app/config/service-account-key.json:/app/config/service-account-key.json:ro \
63-
${{ secrets.DOCKER_HUB_USERNAME }}/commit-api:latest
70+
$DOCKER_HUB_USERNAME/commit-api:latest
6471
6572
echo "⏳ Health check for $TARGET_COLOR..."
6673
for i in {1..10}; do
6774
sleep 2
6875
if curl -s http://localhost:$TARGET_PORT/health | grep "ok" > /dev/null; then
6976
echo "✅ Health check passed. Switching traffic..."
7077
71-
# 심볼릭 링크 변경
72-
ln -sf $TARGET_CONF /opt/app/nginx/default.conf
73-
echo "🔁 Linked $TARGET_CONF to default.conf"
74-
75-
# 현재 심볼릭 링크가 실제로 가리키는 파일 확인
76-
ACTUAL_LINK=$(readlink -f /opt/app/nginx/default.conf)
77-
echo "📌 Current nginx config link points to: $ACTUAL_LINK"
78+
# Switch nginx config inside container
79+
docker exec nginx-proxy cp $TARGET_CONF /etc/nginx/conf.d/default.conf
80+
echo "📋 Switched nginx config to: $TARGET_CONF"
7881
79-
# Nginx reload
8082
docker exec nginx-proxy nginx -s reload
81-
echo "🔄 Nginx config reloaded"
83+
echo "🔄 Nginx reloaded"
8284
83-
# 이전 컨테이너 제거
85+
# Remove previous container
8486
if [ "$TARGET_COLOR" = "blue" ]; then
8587
docker rm -f node-app-green || true
8688
else
@@ -96,4 +98,5 @@ jobs:
9698
echo "❌ Health check failed. Rolling back..."
9799
docker rm -f node-app-$TARGET_COLOR || true
98100
exit 1
101+
99102
EOF

0 commit comments

Comments
 (0)