Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ permissions:

hooks:
BeforeInstall:
- location: scripts/fix-permissions.sh
timeout: 300
runas: root
- location: scripts/download_env.sh
timeout: 2000
runas: ubuntu

AfterInstall:
- location: scripts/after-deploy.sh
timeout: 2000
runas: ubuntu
runas: root

AfterInstall:
- location: scripts/blue-green-deploy.sh
timeout: 2000
runas: ubuntu
runas: root
33 changes: 22 additions & 11 deletions backend/scripts/blue-green-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ echo "DEBUG: ํ˜„์žฌ ์‚ฌ์šฉ์ž: $(whoami)"
echo "DEBUG: ๋””๋ ‰ํ† ๋ฆฌ ๊ถŒํ•œ ํ™•์ธ"
ls -la "$PROJECT_DIR" || echo "๋””๋ ‰ํ† ๋ฆฌ ๋ชฉ๋ก ํ™•์ธ ์‹คํŒจ"

# ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ ์ „์ฒด ์†Œ์œ ์ž root๋กœ ๋ณ€๊ฒฝ
sudo chown -R root:root "$PROJECT_DIR"
# ๋””๋ ‰ํ† ๋ฆฌ๋Š” 755, ํŒŒ์ผ์€ 644๋กœ ๊ถŒํ•œ ์„ค์ •
sudo find "$PROJECT_DIR" -type d -exec chmod 755 {} \;
sudo find "$PROJECT_DIR" -type f -exec chmod 644 {} \;
Expand Down Expand Up @@ -86,24 +88,33 @@ update_nginx_config() {

echo "Nginx ์„ค์ •์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค. ํ™œ์„ฑ ์„œ๋ฒ„: $active_server"

# ๋ฐฑ์—… ์ƒ์„ฑ (๊ถŒํ•œ ๋ฌธ์ œ ๋Œ€์‘)
if ! cp "$NGINX_CONFIG" "$BACKUP_CONFIG" 2>/dev/null; then
echo "โš ๏ธ ๋ฐฑ์—… ํŒŒ์ผ ์ƒ์„ฑ ์‹คํŒจ, ์ž„์‹œ ๋ฐฑ์—… ๊ฒฝ๋กœ ์‚ฌ์šฉ"
BACKUP_CONFIG="/tmp/nginx.conf.backup"
cp "$NGINX_CONFIG" "$BACKUP_CONFIG"
fi
# ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ ์„ค์ •
TEMP_NGINX="/tmp/nginx.conf.temp"
BACKUP_CONFIG="/tmp/nginx.conf.backup"

# ๋ฐฑ์—… ์ƒ์„ฑ
cp "$NGINX_CONFIG" "$BACKUP_CONFIG"

# ์ž„์‹œ ํŒŒ์ผ๋กœ ๋ณต์‚ฌ
cp "$NGINX_CONFIG" "$TEMP_NGINX"

if [ "$active_server" = "blue" ]; then
# blue ํ™œ์„ฑ, green backup
sed -i.bak 's/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Blue ํ™˜๊ฒฝ/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s; # Blue ํ™˜๊ฒฝ/' $NGINX_CONFIG
sed -i.bak 's/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s; # Green ํ™˜๊ฒฝ/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Green ํ™˜๊ฒฝ/' $NGINX_CONFIG
sed 's/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Blue ํ™˜๊ฒฝ/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s; # Blue ํ™˜๊ฒฝ/' "$TEMP_NGINX" > "$TEMP_NGINX.1"
sed 's/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s; # Green ํ™˜๊ฒฝ/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Green ํ™˜๊ฒฝ/' "$TEMP_NGINX.1" > "$TEMP_NGINX.2"
mv "$TEMP_NGINX.2" "$TEMP_NGINX"
else
# green ํ™œ์„ฑ, blue backup
sed -i.bak 's/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s; # Blue ํ™˜๊ฒฝ/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Blue ํ™˜๊ฒฝ/' $NGINX_CONFIG
sed -i.bak 's/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Green ํ™˜๊ฒฝ/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s; # Green ํ™˜๊ฒฝ/' $NGINX_CONFIG
sed 's/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s; # Blue ํ™˜๊ฒฝ/server fastapi-blue:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Blue ํ™˜๊ฒฝ/' "$TEMP_NGINX" > "$TEMP_NGINX.1"
sed 's/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s backup; # Green ํ™˜๊ฒฝ/server fastapi-green:8000 weight=1 max_fails=3 fail_timeout=30s; # Green ํ™˜๊ฒฝ/' "$TEMP_NGINX.1" > "$TEMP_NGINX.2"
mv "$TEMP_NGINX.2" "$TEMP_NGINX"
fi

rm -f ${NGINX_CONFIG}.bak
# ํŽธ์ง‘๋œ ํŒŒ์ผ์„ ์›๋ž˜ ์œ„์น˜๋กœ ๋ณต์‚ฌ
cp "$TEMP_NGINX" "$NGINX_CONFIG"

# ์ž„์‹œ ํŒŒ์ผ ์ •๋ฆฌ
rm -f "$TEMP_NGINX" "$TEMP_NGINX.1" "$TEMP_NGINX.2"
}

# Nginx ๋ฆฌ๋กœ๋“œ
Expand Down
25 changes: 25 additions & 0 deletions backend/scripts/fix-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# ๊ถŒํ•œ ์ˆ˜์ • ์Šคํฌ๋ฆฝํŠธ
echo "๐Ÿ”ง ๋ฐฐํฌ ๋””๋ ‰ํ† ๋ฆฌ ๊ถŒํ•œ ์ˆ˜์ • ์ค‘..."

DEPLOY_DIR="/home/ubuntu/deploy/api_back"

# ๋ฐฐํฌ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜๋ฉด ๊ถŒํ•œ ์ˆ˜์ •
if [ -d "$DEPLOY_DIR" ]; then
echo "๊ธฐ์กด ๋ฐฐํฌ ๋””๋ ‰ํ† ๋ฆฌ ๊ถŒํ•œ ์ˆ˜์ •: $DEPLOY_DIR"
chown -R ubuntu:ubuntu "$DEPLOY_DIR"
chmod -R 755 "$DEPLOY_DIR"
find "$DEPLOY_DIR" -type f -exec chmod 644 {} \;
find "$DEPLOY_DIR" -name "*.sh" -exec chmod 755 {} \;
fi

# CodeDeploy ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ ๊ถŒํ•œ๋„ ์ˆ˜์ •
CODEDEPLOY_ROOT="/opt/codedeploy-agent/deployment-root"
if [ -d "$CODEDEPLOY_ROOT" ]; then
echo "CodeDeploy ๋””๋ ‰ํ† ๋ฆฌ ๊ถŒํ•œ ์ˆ˜์ •: $CODEDEPLOY_ROOT"
find "$CODEDEPLOY_ROOT" -name "deployment-archive" -type d -exec chown -R ubuntu:ubuntu {} \; 2>/dev/null || true
find "$CODEDEPLOY_ROOT" -name "deployment-archive" -type d -exec chmod -R 755 {} \; 2>/dev/null || true
fi

echo "โœ… ๊ถŒํ•œ ์ˆ˜์ • ์™„๋ฃŒ"
Loading