Skip to content

Commit

Permalink
chore : docker-compose.yml를 수정한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed May 7, 2024
1 parent 6b39a94 commit 0e80a66
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 38 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ jobs:
port: 22
script: |
sudo docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker-compose down
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/server
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/batch
sudo chmod +x deploy.sh
sudo chmod +x docker-compose.yml
sudo ./deploy.sh
sudo chmod +x docker-compose.yml
sudo nohup docker-compose up &
# sudo ./deploy.sh
sudo docker image prune -f
56 changes: 30 additions & 26 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,43 @@ else
echo "Docker-compose is already installed"
fi

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

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 $TARGET_SERVICE $BATCH_CONTAINER
#echo "$TARGET_SERVICE Deploy..."
#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

if [ -z "$RUNNING_NGINX" ]; then
echo "Starting Nginx... Changing port to $TARGET_PORT"
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
docker-compose -f /home/ec2-user/docker-compose.yml restart nginx
#if [ -z "$RUNNING_NGINX" ]; then
# echo "Starting Nginx... Changing port to $TARGET_PORT"
# 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
#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

# 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 &
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ 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
server:
container_name: server
image: goodmoneying/server
ports:
- "8082:8080"
- "8080:8080"
restart: "always"

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

batch:
container_name: batch
Expand Down

0 comments on commit 0e80a66

Please sign in to comment.