-
Notifications
You must be signed in to change notification settings - Fork 1
[CHORE] 무중단 배포 #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CHORE] 무중단 배포 #226
Changes from all commits
20688b5
7737547
93bc662
79bbfa0
3a0bd2b
37bbfa1
887a0dc
7dd2776
05809fa
5a6749b
40c0d19
4ba0bf6
48eebce
2708a96
4bdbc4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,4 @@ out/ | |
|
|
||
| ### application-local.yml | ||
| /src/main/resources/application-local.yml | ||
| .serena | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| upstream debate_timer_backend { | ||
| server 127.0.0.1:8080; | ||
| keepalive 32; | ||
| } | ||
|
|
||
| server { | ||
| server_name api.dev.debate-timer.com; | ||
|
|
||
| location / { | ||
| proxy_pass http://debate_timer_backend; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
|
|
||
| listen [::]:443 ssl ipv6only=on; # managed by Certbot | ||
| listen 443 ssl; # managed by Certbot | ||
| ssl_certificate /etc/letsencrypt/live/api.dev.debate-timer.com/fullchain.pem; # managed by Certbot | ||
| ssl_certificate_key /etc/letsencrypt/live/api.dev.debate-timer.com/privkey.pem; # managed by Certbot | ||
| include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | ||
| ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | ||
| } | ||
|
|
||
| server { | ||
| if ($host = api.dev.debate-timer.com) { | ||
| return 308 https://$host$request_uri; | ||
| } # managed by Certbot | ||
|
|
||
| listen 80; | ||
| listen [::]:80; | ||
| server_name api.dev.debate-timer.com; | ||
| return 404; # managed by Certbot | ||
|
Comment on lines
+26
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nginx |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| upstream debate_timer_backend { | ||
| server 127.0.0.1:8080; | ||
| keepalive 32; | ||
| } | ||
|
|
||
| server { | ||
| server_name api.prod.debate-timer.com; | ||
|
|
||
| location / { | ||
| proxy_pass http://debate_timer_backend; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
|
|
||
| listen [::]:443 ssl ipv6only=on; # managed by Certbot | ||
| listen 443 ssl; # managed by Certbot | ||
| ssl_certificate /etc/letsencrypt/live/api.prod.debate-timer.com/fullchain.pem; # managed by Certbot | ||
| ssl_certificate_key /etc/letsencrypt/live/api.prod.debate-timer.com/privkey.pem; # managed by Certbot | ||
| include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | ||
| ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | ||
| } | ||
|
|
||
| server { | ||
| if ($host = api.prod.debate-timer.com) { | ||
| return 308 https://$host$request_uri; | ||
| } # managed by Certbot | ||
|
|
||
| listen 80; | ||
| listen [::]:80; | ||
| server_name api.prod.debate-timer.com; | ||
| return 404; # managed by Certbot | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,238 @@ | ||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| APP_DIR="/home/ubuntu/app" | ||||||||||||||||||||||||||||||||||
| PORT_FILE="$APP_DIR/current_port.txt" | ||||||||||||||||||||||||||||||||||
| LOG_FILE="$APP_DIR/deploy.log" | ||||||||||||||||||||||||||||||||||
| BLUE_PORT=8080 | ||||||||||||||||||||||||||||||||||
| GREEN_PORT=8081 | ||||||||||||||||||||||||||||||||||
| BLUE_MONITOR_PORT=8083 | ||||||||||||||||||||||||||||||||||
| GREEN_MONITOR_PORT=8084 | ||||||||||||||||||||||||||||||||||
| MAX_HEALTH_CHECK_RETRIES=60 | ||||||||||||||||||||||||||||||||||
| HEALTH_CHECK_INTERVAL=2 | ||||||||||||||||||||||||||||||||||
| PROFILE="dev" | ||||||||||||||||||||||||||||||||||
| TIMEZONE="Asia/Seoul" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log() { | ||||||||||||||||||||||||||||||||||
| local timestamp=$(date '+%Y-%m-%d %H:%M:%S') | ||||||||||||||||||||||||||||||||||
| echo "${timestamp} $@" | tee -a "$LOG_FILE" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| error_exit() { | ||||||||||||||||||||||||||||||||||
| log "$1" | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| get_current_port() { | ||||||||||||||||||||||||||||||||||
| if [ ! -f "$PORT_FILE" ]; then | ||||||||||||||||||||||||||||||||||
| log "Port file not found. Initializing with default port $BLUE_PORT" | ||||||||||||||||||||||||||||||||||
| echo "$BLUE_PORT" > "$PORT_FILE" | ||||||||||||||||||||||||||||||||||
| echo "$BLUE_PORT" | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| cat "$PORT_FILE" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| get_inactive_port() { | ||||||||||||||||||||||||||||||||||
| local current_port=$1 | ||||||||||||||||||||||||||||||||||
| if [ "$current_port" -eq "$BLUE_PORT" ]; then | ||||||||||||||||||||||||||||||||||
| echo "$GREEN_PORT" | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "$BLUE_PORT" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| get_monitor_port() { | ||||||||||||||||||||||||||||||||||
| local app_port=$1 | ||||||||||||||||||||||||||||||||||
| if [ "$app_port" -eq "$BLUE_PORT" ]; then | ||||||||||||||||||||||||||||||||||
| echo "$BLUE_MONITOR_PORT" | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "$GREEN_MONITOR_PORT" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| is_port_in_use() { | ||||||||||||||||||||||||||||||||||
| local port=$1 | ||||||||||||||||||||||||||||||||||
| sudo lsof -t -i:$port > /dev/null 2>&1 | ||||||||||||||||||||||||||||||||||
| return $? | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| kill_process_on_port() { | ||||||||||||||||||||||||||||||||||
| local port=$1 | ||||||||||||||||||||||||||||||||||
| local pid=$(sudo lsof -t -i:$port 2>/dev/null) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if [ -z "$pid" ]; then | ||||||||||||||||||||||||||||||||||
| log "No process running on port $port" | ||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Sending graceful shutdown signal to process $pid on port $port" | ||||||||||||||||||||||||||||||||||
| sudo kill -15 "$pid" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| local wait_count=0 | ||||||||||||||||||||||||||||||||||
| while [ $wait_count -lt 65 ] && is_port_in_use "$port"; do | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait_count 65초 정도로 대기 시간을 설정한 이유가 있나요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 큰 이유는 없습니다. shutdown의 시간보다 5초정도 더 여유를 줬습니다 |
||||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||||
| wait_count=$((wait_count + 1)) | ||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if is_port_in_use "$port"; then | ||||||||||||||||||||||||||||||||||
| log "Process didn't stop gracefully, forcing shutdown" | ||||||||||||||||||||||||||||||||||
| sudo kill -9 "$pid" 2>/dev/null || true | ||||||||||||||||||||||||||||||||||
| sleep 2 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Process on port $port stopped successfully" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| health_check() { | ||||||||||||||||||||||||||||||||||
| local port=$1 | ||||||||||||||||||||||||||||||||||
| local monitor_port=$2 | ||||||||||||||||||||||||||||||||||
| local health_url="http://localhost:$monitor_port/monitoring/health" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Starting health check for port $port (monitor: $monitor_port)" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| local retry=1 | ||||||||||||||||||||||||||||||||||
| while [ $retry -le $MAX_HEALTH_CHECK_RETRIES ]; do | ||||||||||||||||||||||||||||||||||
| local status=$(curl -s -o /dev/null -w "%{http_code}" "$health_url" 2>/dev/null || echo "000") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Health check attempt $retry/$MAX_HEALTH_CHECK_RETRIES - Status: $status" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if [ "$status" = "200" ]; then | ||||||||||||||||||||||||||||||||||
| log "Health check passed!" | ||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sleep $HEALTH_CHECK_INTERVAL | ||||||||||||||||||||||||||||||||||
| retry=$((retry + 1)) | ||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Health check failed after $MAX_HEALTH_CHECK_RETRIES attempts" | ||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| start_application() { | ||||||||||||||||||||||||||||||||||
| local port=$1 | ||||||||||||||||||||||||||||||||||
| local monitor_port=$2 | ||||||||||||||||||||||||||||||||||
| local staging_jar="$APP_DIR/staging/app.jar" | ||||||||||||||||||||||||||||||||||
| local jar_file="$APP_DIR/app-$port.jar" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if [ ! -f "$staging_jar" ]; then | ||||||||||||||||||||||||||||||||||
| error_exit "No JAR file found in staging directory: $staging_jar" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Copying JAR from staging to $jar_file" | ||||||||||||||||||||||||||||||||||
| cp "$staging_jar" "$jar_file" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Starting application on port $port with JAR: $jar_file" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if is_port_in_use "$port"; then | ||||||||||||||||||||||||||||||||||
| log "Port $port is in use, cleaning up..." | ||||||||||||||||||||||||||||||||||
| kill_process_on_port "$port" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sudo nohup java \ | ||||||||||||||||||||||||||||||||||
| -Dspring.profiles.active=$PROFILE,monitor \ | ||||||||||||||||||||||||||||||||||
| -Duser.timezone=$TIMEZONE \ | ||||||||||||||||||||||||||||||||||
| -Dserver.port=$port \ | ||||||||||||||||||||||||||||||||||
| -Dmanagement.server.port=$monitor_port \ | ||||||||||||||||||||||||||||||||||
| -Ddd.service=debate-timer \ | ||||||||||||||||||||||||||||||||||
| -Ddd.env=$PROFILE \ | ||||||||||||||||||||||||||||||||||
| -jar "$jar_file" > "$APP_DIR/app-$port.log" 2>&1 & | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+134
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check if file exists and read lines 134-141
if [ -f "scripts/dev/zero-downtime-deploy.sh" ]; then
echo "=== Lines 130-145 of zero-downtime-deploy.sh ==="
sed -n '130,145p' scripts/dev/zero-downtime-deploy.sh | cat -n
else
echo "File not found"
fiRepository: debate-timer/debate-timer-be Length of output: 704 🌐 Web query:
💡 Result: The shell (your unprivileged shell) performs the redirection before sudo runs the command — so sudo applies to the command being run, not to the > or >> open that writes the file. [1][2][3] Common fixes:
Sources: [1] Stack Overflow, [2] Baeldung, [3] ShellHacks. 🏁 Script executed: # Also check for application logging configuration
echo "=== Check for logging in application configuration files ==="
find . -type f \( -name "application*.yml" -o -name "application*.properties" \) 2>/dev/null | head -5
echo -e "\n=== Check surrounding context of the deploy script ==="
if [ -f "scripts/dev/zero-downtime-deploy.sh" ]; then
wc -l scripts/dev/zero-downtime-deploy.sh
fiRepository: debate-timer/debate-timer-be Length of output: 437 Critical: sudo does not apply to output redirection (SC2024 logic issue) The redirection - sudo nohup java \
+ sudo sh -c 'nohup java \
-Dspring.profiles.active=$PROFILE,monitor \
-Duser.timezone=$TIMEZONE \
-Dserver.port=$port \
-Dmanagement.server.port=$monitor_port \
-Ddd.service=debate-timer \
-Ddd.env=$PROFILE \
- -jar "$jar_file" > "$APP_DIR/app-$port.log" 2>&1 &
+ -jar "$jar_file" > "$APP_DIR/app-$port.log" 2>&1 &'Alternatively, verify that Java logging is properly configured via 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.11.0)[warning] 141-141: sudo doesn't affect redirects. Use ..| sudo tee file (SC2024) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| local pid=$! | ||||||||||||||||||||||||||||||||||
| log "Application started with PID: $pid" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sleep 3 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ! kill -0 $pid 2>/dev/null; then | ||||||||||||||||||||||||||||||||||
| error_exit "Application process died immediately after start. Check logs at $APP_DIR/app-$port.log" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| switch_nginx_upstream() { | ||||||||||||||||||||||||||||||||||
| local new_port=$1 | ||||||||||||||||||||||||||||||||||
| local nginx_conf="/etc/nginx/sites-available/api.dev.debate-timer.com" | ||||||||||||||||||||||||||||||||||
| local temp_conf="/tmp/api.dev.debate-timer.com.tmp" | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 임시 파일 경로로
# 스크립트 상단에 추가
temp_conf=$(mktemp)
trap 'rm -f "$temp_conf"' EXIT INT TERM이 변경 사항은
Suggested change
|
||||||||||||||||||||||||||||||||||
| local backup_conf="${nginx_conf}.bak" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if [ ! -f "$nginx_conf" ]; then | ||||||||||||||||||||||||||||||||||
| error_exit "nginx configuration not found at $nginx_conf" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Switching nginx upstream to port $new_port" | ||||||||||||||||||||||||||||||||||
| sudo cp "$nginx_conf" "$backup_conf" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sed "s/server 127\.0\.0\.1:[0-9]\+;/server 127.0.0.1:$new_port;/" "$nginx_conf" > "$temp_conf" | ||||||||||||||||||||||||||||||||||
| sudo cp "$temp_conf" "$nginx_conf" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ! sudo nginx -t 2>/dev/null; then | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
배포 실패 시 원인을 빠르게 파악하기 위해 에러 메시지를 로그 파일에 기록하는 것이 좋습니다. 이 변경 사항은
Suggested change
|
||||||||||||||||||||||||||||||||||
| log "nginx configuration test failed, rolling back." | ||||||||||||||||||||||||||||||||||
| sudo cp "$backup_conf" "$nginx_conf" | ||||||||||||||||||||||||||||||||||
| sudo rm "$backup_conf" | ||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sudo nginx -s reload | ||||||||||||||||||||||||||||||||||
| log "nginx reloaded successfully" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sleep 2 | ||||||||||||||||||||||||||||||||||
| local response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost/" 2>/dev/null || echo "000") | ||||||||||||||||||||||||||||||||||
| if [ "$response" = "000" ] || [ "$response" = "502" ] || [ "$response" = "503" ]; then | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+180
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| log "nginx health check failed after reload (status: $response). Rolling back nginx config." | ||||||||||||||||||||||||||||||||||
| sudo cp "$backup_conf" "$nginx_conf" | ||||||||||||||||||||||||||||||||||
| sudo nginx -s reload | ||||||||||||||||||||||||||||||||||
| sudo rm "$backup_conf" | ||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "nginx is now routing traffic to port $new_port" | ||||||||||||||||||||||||||||||||||
| sudo rm "$backup_conf" | ||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| main() { | ||||||||||||||||||||||||||||||||||
| local current_port=$(get_current_port) | ||||||||||||||||||||||||||||||||||
| local new_port=$(get_inactive_port "$current_port") | ||||||||||||||||||||||||||||||||||
| local new_monitor_port=$(get_monitor_port "$new_port") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Current active port: $current_port" | ||||||||||||||||||||||||||||||||||
| log "Deploying to port: $new_port" | ||||||||||||||||||||||||||||||||||
| log "Monitor port: $new_monitor_port" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Step 1/4: Starting new version on port $new_port" | ||||||||||||||||||||||||||||||||||
| start_application "$new_port" "$new_monitor_port" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Step 2/4: Performing health check" | ||||||||||||||||||||||||||||||||||
| if ! health_check "$new_port" "$new_monitor_port"; then | ||||||||||||||||||||||||||||||||||
| log "Deployment failed: Health check did not pass" | ||||||||||||||||||||||||||||||||||
| log "Rolling back: Stopping new version on port $new_port" | ||||||||||||||||||||||||||||||||||
| kill_process_on_port "$new_port" | ||||||||||||||||||||||||||||||||||
| error_exit "Deployment aborted due to health check failure" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Step 3/4: Switching nginx to new version" | ||||||||||||||||||||||||||||||||||
| if ! switch_nginx_upstream "$new_port"; then | ||||||||||||||||||||||||||||||||||
| log "nginx switch failed, rolling back" | ||||||||||||||||||||||||||||||||||
| kill_process_on_port "$new_port" | ||||||||||||||||||||||||||||||||||
| error_exit "Deployment aborted due to nginx switch failure" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Step 4/4: Stopping old version on port $current_port" | ||||||||||||||||||||||||||||||||||
| kill_process_on_port "$current_port" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| local old_jar="$APP_DIR/app-$current_port.jar" | ||||||||||||||||||||||||||||||||||
| if [ -f "$old_jar" ]; then | ||||||||||||||||||||||||||||||||||
| log "Removing old JAR file: $old_jar" | ||||||||||||||||||||||||||||||||||
| rm -f "$old_jar" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| echo "$new_port" > "$PORT_FILE" | ||||||||||||||||||||||||||||||||||
| log "Updated active port file to $new_port" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| log "Deployment completed successfully!" | ||||||||||||||||||||||||||||||||||
| log "Active port: $new_port" | ||||||||||||||||||||||||||||||||||
| log "Inactive port: $current_port" | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| main "$@" | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
두 스크립트를 하나로 통합하고, 환경(dev/prod)을 인자로 받아 동적으로 설정을 변경하도록 리팩토링하는 것을 강력히 권장합니다. 예시: 이렇게 하면 |
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nginx 파일을 전부 여기에서 관리하는 이유가 있을까요?
(일부는 Certbot 측에서 관리하다 보니, Certbot에서 해당 파일을 바꿔버리면 여기 적용 안될 것 같은데;;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 단지 코드 관리 측면에서 업로드 한 것일 뿐 실제로 깃허브에 있는 이 파일을 사용하지는 않습니다. 제가 직접 ec2에 접속해 수정한 뒤 어떻게 수정한지를 기록한 것입니다.