Skip to content

Commit d444586

Browse files
ImTotemclaude
andcommitted
refactor(infra): nginx conf envsubst template, no more hardcoded ports/domains
- Rename bcsd-api.conf → bcsd-api.conf.template with ${VAR} placeholders - deploy.sh renders template via envsubst before nginx install - All ports (API_BLUE_PORT, API_GREEN_PORT, N8N_PORT, FRONTEND_PORT) and domains (DOMAIN, N8N_DOMAIN, FRONTEND_DOMAIN) from .env - Add FRONTEND_PORT=3080 to .env.example - Generated .conf added to .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d95e7b commit d444586

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ API_BLUE_PORT=8001
4444
API_GREEN_PORT=8002
4545
# n8n 호스트 포트
4646
N8N_PORT=5678
47+
# 프론트엔드 호스트 포트
48+
FRONTEND_PORT=3080
4749
# Graceful shutdown 대기 시간 (초)
4850
GRACEFUL_TIMEOUT=10
4951

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,5 +511,8 @@ $RECYCLE.BIN/
511511
!package.json
512512
!tsconfig.json
513513

514+
# Generated nginx conf (envsubst output from .template)
515+
infra/nginx/bcsd-api.conf
516+
514517
# End of https://www.toptal.com/developers/gitignore/api/intellij+all,pycharm+all,visualstudiocode,python,pythonvanilla,macos,windows,linux,git,jetbrains+all
515518

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ map $http_upgrade $connection_upgrade {
44
}
55

66
upstream api_blue {
7-
server 127.0.0.1:8001;
7+
server 127.0.0.1:${API_BLUE_PORT};
88
}
99

1010
upstream api_green {
11-
server 127.0.0.1:8002;
11+
server 127.0.0.1:${API_GREEN_PORT};
1212
}
1313

1414
upstream n8n {
15-
server 127.0.0.1:5678;
15+
server 127.0.0.1:${N8N_PORT};
1616
}
1717

1818
upstream frontend {
19-
server 127.0.0.1:3080;
19+
server 127.0.0.1:${FRONTEND_PORT};
2020
}
2121

2222
# --- HTTP: ACME + redirect ---
2323
server {
2424
listen 80;
25-
server_name api.bcsdlab.com n8n.bcsdlab.com stage.bcsdlab.com;
25+
server_name ${DOMAIN} ${N8N_DOMAIN} ${FRONTEND_DOMAIN};
2626

2727
location /.well-known/acme-challenge/ {
2828
root /var/www/certbot;
@@ -36,7 +36,7 @@ server {
3636
# --- HTTPS: API ---
3737
server {
3838
listen 443 ssl http2;
39-
server_name api.bcsdlab.com;
39+
server_name ${DOMAIN};
4040

4141
ssl_certificate /etc/letsencrypt/live/bcsdlab.com/fullchain.pem;
4242
ssl_certificate_key /etc/letsencrypt/live/bcsdlab.com/privkey.pem;
@@ -76,7 +76,7 @@ server {
7676
# --- HTTPS: Frontend ---
7777
server {
7878
listen 443 ssl http2;
79-
server_name stage.bcsdlab.com;
79+
server_name ${FRONTEND_DOMAIN};
8080

8181
ssl_certificate /etc/letsencrypt/live/bcsdlab.com/fullchain.pem;
8282
ssl_certificate_key /etc/letsencrypt/live/bcsdlab.com/privkey.pem;
@@ -126,7 +126,7 @@ server {
126126
# --- HTTPS: n8n ---
127127
server {
128128
listen 443 ssl http2;
129-
server_name n8n.bcsdlab.com;
129+
server_name ${N8N_DOMAIN};
130130

131131
ssl_certificate /etc/letsencrypt/live/bcsdlab.com/fullchain.pem;
132132
ssl_certificate_key /etc/letsencrypt/live/bcsdlab.com/privkey.pem;

infra/scripts/deploy.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ set -euo pipefail
33

44
COMPOSE="sudo docker compose -p bcsd-app --env-file .env -f infra/docker/docker-compose.yml"
55
COMPOSE_DB="sudo docker compose -p bcsd-db --env-file .env -f infra/docker/docker-compose.db.yml"
6+
NGINX_TEMPLATE="infra/nginx/bcsd-api.conf.template"
67
NGINX_CONF="infra/nginx/bcsd-api.conf"
78
NGINX_AVAILABLE="/etc/nginx/sites-available/bcsd-api.conf"
89
NGINX_ENABLED="/etc/nginx/sites-enabled/bcsd-api.conf"
910
HEALTH_PATH="/openapi.json"
1011
MAX_RETRIES=10
12+
ENVSUBST_VARS='${API_BLUE_PORT} ${API_GREEN_PORT} ${N8N_PORT} ${FRONTEND_PORT} ${DOMAIN} ${N8N_DOMAIN} ${FRONTEND_DOMAIN}'
1113

1214
current_slot() {
13-
grep proxy_pass "$NGINX_CONF" | grep -q "api_blue" && echo "blue" || echo "green"
15+
grep proxy_pass "$NGINX_CONF" 2>/dev/null | grep -q "api_blue" && echo "blue" || echo "green"
1416
}
1517

1618
next_slot() {
@@ -49,13 +51,20 @@ check_credentials() {
4951
fi
5052
}
5153

54+
render_nginx() {
55+
set -a; source .env; set +a
56+
envsubst "$ENVSUBST_VARS" < "$NGINX_TEMPLATE" > "$NGINX_CONF"
57+
}
58+
5259
echo "=== BCSD API Blue-Green Deploy ==="
5360

5461
check_credentials
5562

5663
echo "0. Ensuring DB services..."
5764
$COMPOSE_DB up -d
5865

66+
render_nginx
67+
5968
CURRENT=$(current_slot)
6069
NEXT=$(next_slot)
6170

0 commit comments

Comments
 (0)