Skip to content

Commit

Permalink
feat: blue green 무중단 배포 스크립트
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee committed Oct 15, 2024
1 parent d9dc16f commit b1effee
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions .github/workflows/backend-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ jobs:
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_BE_PROD }}
- name: Wait for Application Booting 30 seconds
run: sleep 30
run: |
echo "Waiting for the application to boot..."
for ((i=1;i<=30;i++)); do
echo -n "."
sleep 1
done
echo # 줄바꿈
- name: Health check the new container
id: health-check
Expand All @@ -113,53 +119,47 @@ jobs:
- name: Update or create Nginx container to point to new container port
run: |
NGINX_CONTAINER_NAME="nginx-proxy"
echo "Checking if Nginx container is running..."

# Check if the Nginx container exists
echo "Checking if Nginx container exists..."
if sudo docker ps -a --filter "name=$NGINX_CONTAINER_NAME" --format "{{.Names}}" | grep -w $NGINX_CONTAINER_NAME; then
# Check if the Nginx container is running
# 컨테이너가 실행 중인지 확인
if sudo docker ps --filter "name=$NGINX_CONTAINER_NAME" --format "{{.Names}}" | grep -w $NGINX_CONTAINER_NAME; then
echo "Nginx container is running. Updating configuration..."
echo "Nginx container is running."
else
echo "Nginx container exists but is not running. Starting Nginx container..."
sudo docker start $NGINX_CONTAINER_NAME
echo "Nginx container started."
fi

# Copy Nginx config from the running container to the host
sudo docker cp $NGINX_CONTAINER_NAME:/etc/nginx/nginx.conf ./nginx.conf

# Update the proxy_pass setting in the config file
# 호스트의 nginx.conf 파일을 수정
echo "Updating Nginx configuration file on host..."
sudo sed -i "s/proxy_pass http:\/\/127.0.0.1:.*;/proxy_pass http:\/\/127.0.0.1:${{ steps.check-port.outputs.next_port }};/" ./nginx.conf

# Copy the updated config back into the container
sudo docker cp ./nginx.conf $NGINX_CONTAINER_NAME:/etc/nginx/nginx.conf

# Reload Nginx inside the container
# 컨테이너 내부에서 Nginx를 재로드
echo "Reloading Nginx inside the container..."
sudo docker exec $NGINX_CONTAINER_NAME nginx -s reload
echo "Nginx configuration updated and reloaded."
else
echo "Nginx container not found. Creating a new Nginx container..."
# Create a basic Nginx config file with the updated proxy_pass
# nginx.conf 파일 생성
echo "
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:${{ steps.check-port.outputs.next_port }};
proxy_pass http://127.0.0.1:${{ steps.check-port.outputs.next_port }};
}
}
}
" > ./nginx.conf
# Run a new Nginx container with the updated config
sudo docker run -d --name $NGINX_CONTAINER_NAME -p 80:80 \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro nginx
echo "New Nginx container created and running."
" > ./nginx.conf
# 새로운 Nginx 컨테이너 실행
sudo docker run -d --name $NGINX_CONTAINER_NAME -p 80:80 \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro nginx
echo "New Nginx container created and running."
fi
- name: Stop and remove the old container
Expand Down

0 comments on commit b1effee

Please sign in to comment.