Skip to content

Commit

Permalink
chore : blue-green 전략을 다시 도입한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed May 7, 2024
1 parent 9c72207 commit 69faacf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
38 changes: 16 additions & 22 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,25 @@ else
echo "Docker-compose is already installed"
fi

#RUNNING_CONTAINER=$(docker ps | grep blue)
RUNNING_CONTAINER=$(docker ps | grep blue)
NGINX_CONF="/home/ec2-user/data/nginx/app.conf"
RUNNING_NGINX=$(docker ps | grep nginx)
BATCH_CONTAINER="batch"
SERVER_CONTAINER="server"

#if [ -z "$RUNNING_CONTAINER" ]; then
# TARGET_SERVICE="blue-api"
# OTHER_SERVICE="green-api"
# TARGET_PORT="8082"
# OTHER_PORT="8081"
#else
# TARGET_SERVICE="green-api"
# OTHER_SERVICE="blue-api"
# TARGET_PORT="8081"
# OTHER_PORT="8082"
#fi
if [ -z "$RUNNING_CONTAINER" ]; then
TARGET_SERVICE="blue-api"
OTHER_SERVICE="green-api"
TARGET_PORT="8082"
OTHER_PORT="8081"
else
TARGET_SERVICE="green-api"
OTHER_SERVICE="blue-api"
TARGET_PORT="8081"
OTHER_PORT="8082"
fi

#echo "$TARGET_SERVICE Deploy..."
docker-compose -f /home/ec2-user/docker-compose.yml up -d $SERVER_CONTAINER $BATCH_CONTAINER
docker-compose -f /home/ec2-user/docker-compose.yml up -d $TARGET_SERVICE $BATCH_CONTAINER

# Wait for the target service to be healthy before proceeding
sleep 10
Expand All @@ -56,15 +55,10 @@ if [ -z "$RUNNING_NGINX" ]; then
docker-compose -f /home/ec2-user/docker-compose.yml up -d nginx
fi

#
# Update the nginx config and reload
#sed -i "s/$OTHER_SERVICE/$TARGET_SERVICE/" $NGINX_CONF
#sed -i "s/$OTHER_PORT/$TARGET_PORT/" $NGINX_CONF
sed -i "s/$OTHER_SERVICE/$TARGET_SERVICE/" $NGINX_CONF
sed -i "s/$OTHER_PORT/$TARGET_PORT/" $NGINX_CONF
docker-compose -f /home/ec2-user/docker-compose.yml restart nginx

# Stop the other service
#docker-compose -f /home/ec2-user/docker-compose.yml stop $OTHER_SERVICE

# docker-compose down & up
#nohup docker-compose -f /home/ec2-user/docker-compose.yml down > /dev/null 2>&1 &
#nohup docker-compose -f /home/ec2-user/docker-compose.yml up -d > /dev/null 2>&1 &
docker-compose -f /home/ec2-user/docker-compose.yml stop $OTHER_SERVICE
18 changes: 12 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
nginx:
container_name: nginx
image: nginx:1.15-alpine
image: nginx:latest
ports:
- 80:80
- 443:443
Expand All @@ -11,15 +11,21 @@ services:
- ./data/nginx/log:/var/log/nginx
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
depends_on:
- "server"
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
restart: "always"

blue-api:
container_name: blue-api
image: goodmoneying/server
ports:
- "8082:8080"
restart: "always"

server:
container_name: server
green-api:
container_name: green-api
image: goodmoneying/server
ports:
- "8080:8080"
- "8081:8080"
restart: "always"

batch:
Expand Down

0 comments on commit 69faacf

Please sign in to comment.