-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
944011c
commit fee4227
Showing
9 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
echo "Building new version deployment" | ||
cd /home/ubuntu/develop/backend | ||
cp -R /home/ubuntu/develop/backend/build/libs/* build/libs_new/ | ||
|
||
# 현재 실행 중인 컨테이너 확인 | ||
CURRENT_CONTAINER=$(docker ps --filter "name=campride-api-server" --format "{{.Names}}") | ||
if [ "$CURRENT_CONTAINER" == "campride-api-server-blue" ]; then | ||
NEW_CONTAINER="campride-api-server-green" | ||
else | ||
NEW_CONTAINER="campride-api-server-blue" | ||
fi | ||
|
||
# 새 버전의 이미지 빌드 | ||
docker-compose build $NEW_CONTAINER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "Cleaning up old deployment artifacts" | ||
cd /home/ubuntu/develop/backend | ||
docker image prune -af |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "Preparing for new deployment" | ||
cd /home/ubuntu/develop/backend | ||
mkdir -p build/libs_new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
echo "Starting new version" | ||
cd /home/ubuntu/develop/backend | ||
|
||
# 현재 실행 중인 컨테이너 확인 | ||
CURRENT_CONTAINER=$(docker ps --filter "name=campride-api-server" --format "{{.Names}}") | ||
if [ "$CURRENT_CONTAINER" == "campride-api-server-blue" ]; then | ||
NEW_CONTAINER="campride-api-server-green" | ||
NEW_PORT=8081 | ||
CURRENT_PORT=8080 | ||
else | ||
NEW_CONTAINER="campride-api-server-blue" | ||
NEW_PORT=8080 | ||
CURRENT_PORT=8081 | ||
fi | ||
|
||
# 새 컨테이너 시작 | ||
docker-compose up -d $NEW_CONTAINER | ||
|
||
# 새 컨테이너가 준비될 때까지 대기 | ||
echo "Waiting for the new container to be ready..." | ||
for i in {1..30}; do | ||
if curl -s http://localhost:$NEW_PORT/actuator/health | grep -q "UP"; then | ||
echo "New container is ready" | ||
break | ||
fi | ||
if [ $i -eq 30 ]; then | ||
echo "New container failed to start" | ||
exit 1 | ||
fi | ||
sleep 10 | ||
done | ||
|
||
# Nginx 설정 업데이트 | ||
NGINX_CONF="/home/ubuntu/develop/backend/data/nginx/nginx.conf" | ||
sed -i "s/proxy_pass http:\/\/$CURRENT_CONTAINER:$CURRENT_PORT/proxy_pass http:\/\/$NEW_CONTAINER:$NEW_PORT/" $NGINX_CONF | ||
|
||
# Nginx 설정 리로드 | ||
docker-compose exec -T nginx nginx -s reload | ||
|
||
echo "Switched traffic to $NEW_CONTAINER on port $NEW_PORT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
echo "Validating new deployment" | ||
cd /home/ubuntu/develop/backend | ||
|
||
# 현재 활성 컨테이너 확인 | ||
NEW_CONTAINER=$(docker ps --filter "name=campride-api-server" --format "{{.Names}}") | ||
OLD_CONTAINER=$(docker ps -a --filter "name=campride-api-server" --filter "status=exited" --format "{{.Names}}") | ||
|
||
# 새 버전 상태 확인 | ||
for i in {1..5}; do | ||
response=$(curl -sS http://localhost:8080/actuator/health) | ||
if [[ $response == *"UP"* ]]; then | ||
echo "New version is healthy" | ||
# 새 버전의 라이브러리를 메인 디렉토리로 이동 | ||
mv build/libs build/libs_old | ||
mv build/libs_new build/libs | ||
# 이전 버전 컨테이너 중지 | ||
docker-compose stop $OLD_CONTAINER | ||
exit 0 | ||
fi | ||
sleep 10 | ||
done | ||
|
||
echo "New version is not healthy. Rolling back." | ||
|
||
# 롤백 | ||
NGINX_CONF="/home/ubuntu/develop/backend/data/nginx/nginx.conf" | ||
sed -i "s/proxy_pass http:\/\/$NEW_CONTAINER:8080/proxy_pass http:\/\/$OLD_CONTAINER:8080/" $NGINX_CONF | ||
docker-compose exec -T nginx nginx -s reload | ||
docker-compose stop $NEW_CONTAINER | ||
docker-compose start $OLD_CONTAINER | ||
echo "Rolled back to $OLD_CONTAINER" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters