Skip to content

Commit 91b879c

Browse files
committed
[FIX] CD 설정 수정
1 parent b33c9a9 commit 91b879c

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

.github/workflows/cd.yml

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

3636
- name: Deploy with Blue-Green
3737
run: |
38-
ssh ec2 "DOCKER_HUB_USERNAME=${{ secrets.DOCKER_HUB_USERNAME }} bash -s" <<'EOF'
39-
38+
ssh ec2 <<'EOF'
4039
echo "📦 Pulling latest image..."
41-
docker pull $DOCKER_HUB_USERNAME/commit-api:latest
40+
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/commit-api:latest
4241
4342
echo "🔍 Checking current active environment..."
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
43+
ACTIVE_COLOR=$(docker exec nginx-proxy grep -Po '(?<=proxy_pass http://)node-app-(blue|green)' /etc/nginx/conf.d/default.conf | cut -d'-' -f3)
5044
51-
if echo "$CURRENT" | grep -q "blue"; then
45+
if [ "$ACTIVE_COLOR" = "blue" ]; then
5246
TARGET_COLOR=green
5347
TARGET_PORT=3001
5448
TARGET_CONF=/etc/nginx/conf.d/default-green.conf.disabled
@@ -67,22 +61,20 @@ jobs:
6761
-p $TARGET_PORT:3000 \
6862
--network=commit-networks \
6963
-v /opt/app/config/service-account-key.json:/app/config/service-account-key.json:ro \
70-
$DOCKER_HUB_USERNAME/commit-api:latest
64+
${{ secrets.DOCKER_HUB_USERNAME }}/commit-api:latest
7165
7266
echo "⏳ Health check for $TARGET_COLOR..."
7367
for i in {1..10}; do
7468
sleep 2
7569
if curl -s http://localhost:$TARGET_PORT/health | grep "ok" > /dev/null; then
7670
echo "✅ Health check passed. Switching traffic..."
7771
78-
# Switch nginx config inside container
7972
docker exec nginx-proxy cp $TARGET_CONF /etc/nginx/conf.d/default.conf
8073
echo "📋 Switched nginx config to: $TARGET_CONF"
8174
8275
docker exec nginx-proxy nginx -s reload
8376
echo "🔄 Nginx reloaded"
8477
85-
# Remove previous container
8678
if [ "$TARGET_COLOR" = "blue" ]; then
8779
docker rm -f node-app-green || true
8880
else
@@ -98,5 +90,4 @@ jobs:
9890
echo "❌ Health check failed. Rolling back..."
9991
docker rm -f node-app-$TARGET_COLOR || true
10092
exit 1
101-
10293
EOF

0 commit comments

Comments
 (0)