-
Notifications
You must be signed in to change notification settings - Fork 0
[FEATURE] Docker 기반 Blue/Gren 무중단배포 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
35ebb67
eb49336
999c6ce
494d3c1
b5a1236
71b6f13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ERR_MSG='' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| trap 'echo "Error occured: $ERR_MSG. Exiting deploy script."; exit 1' ERR | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 현재 포트 파악 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if sudo docker ps --filter "name=app-blue" --quiet | grep -E .; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Blue down, Green Up " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| BEFORE_COMPOSE_COLOR="blue" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| AFTER_COMPOSE_COLOR="green" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| HOST_PORT="8001" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Green down, Blue up" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| BEFORE_COMPOSE_COLOR="green" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| AFTER_COMPOSE_COLOR="blue" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| HOST_PORT="8000" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 실행 중인 컨테이너 상태를 설명하는
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Pulling image: ${IMAGE}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # docker pull | ||||||||||||||||||||||||||||||||||||||||||||||||||
| docker compose pull ${ECR_URI}/dearbelly-cv:latest | ||||||||||||||||||||||||||||||||||||||||||||||||||
| docker compose up -d --no-deps --force-recreate app-${AFTER_COMPOSE_COLOR} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 새 컨테이너가 running 될 때까지 대기 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in $(seq 1 60); do | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if docker ps --filter "name=^/app-${AFTER_COLOR}$" --filter "status=running" --format '{{.Names}}' | grep -q .; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "New app-${AFTER_COLOR} container is running." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "$i" -eq 60 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "New container failed to start in time." >&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 헬스 체크는 컨테이너가 애플리케이션에
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 새로운 컨테이너 확인 후 Nginx 설정 변경 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if docker ps --filter "name=app-${AFTER_COMPOSE_COLOR}" --filter "status=running" --format '{{.Names}}' | grep -q .; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "New app-${AFTER_COMPOSE_COLOR} container is running." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # reload nginx | ||||||||||||||||||||||||||||||||||||||||||||||||||
| NGINX_ID=$(sudo docker ps --filter "name=nginx" --quiet) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| NGINX_CONFIG="/home/ubuntu/deployment/nginx.conf" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Switching Nginx upstream config..." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! sed -i "s/app-${BEFORE_COMPOSE_COLOR}:8000/app-${AFTER_COMPOSE_COLOR}:8000/" $NGINX_CONFIG; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Error occured: Failed to update Nginx config. Exiting deploy script." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Reloding Nginx in Container" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! docker exec $NGINX_ID nginx -s reload; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ERR_MSG='Failed to update Nginx config' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! docker compose restart nginx; then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ERR_MSG='Failed to reload Nginx' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 이전 컨테이너 종료 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| docker stop app-${BEFORE_COMPOSE_COLOR} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| docker rm app-${BEFORE_COMPOSE_COLOR} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| docker image prune -af | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Deployment success." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| services: | ||
| app-blue: | ||
| image: ${ECR_URI}/dearbelly-dv:latest | ||
| ports: | ||
| - "8000:8000" | ||
| env_file: | ||
| - /home/ubuntu/dearbelly/deployment/.env | ||
| deploy: | ||
| resources: | ||
| reservations: | ||
| devices: | ||
| - driver: nvidia | ||
| count: 1 | ||
| capabilities: [gpu] | ||
| container_name: app-blue | ||
|
|
||
| app-green: | ||
| image: ${ECR_URI}/dearbelly-dv:latest | ||
| ports: | ||
| - "8001:8000" | ||
| env_file: | ||
| - /home/ubuntu/dearbelly/deployment/.env | ||
| deploy: | ||
| resources: | ||
| reservations: | ||
| devices: | ||
| - driver: nvidia | ||
| count: 1 | ||
| capabilities: [ gpu ] | ||
| container_name: app-green |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| events {} | ||
|
|
||
| http { | ||
| upstream backend { | ||
| server app-blue:8000; | ||
| } | ||
|
|
||
| server { | ||
| listen 80; | ||
|
|
||
| location / { | ||
| proxy_pass http://backend/; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
|
|
||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
|
|
||
| } | ||
|
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기본적인 프록시 설정은 올바릅니다. 하지만 더 안정적인 운영을 위해 프록시 관련 타임아웃 설정을 추가하는 것을 고려해 보세요. 예를 들어, 백엔드 서버의 응답이 느릴 경우를 대비해 location / {
proxy_pass http://backend/;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재
WORKDIR가/app으로 설정되어 있고,COPY . .명령어로 인해requirements.txt파일은/app/requirements.txt에 위치하게 됩니다. 하지만RUN명령어에서-r app/requirements.txt를 사용하고 있어,/app/app/requirements.txt경로를 찾게 되어 빌드가 실패합니다. 올바른 경로인requirements.txt로 수정해야 합니다.추가적으로, Docker 빌드 캐시를 더 효율적으로 활용하기 위해
requirements.txt파일을 먼저 복사하고 의존성을 설치한 후에 나머지 애플리케이션 코드를 복사하는 것을 고려해보세요. 이렇게 하면 빌드 시간을 단축할 수 있습니다.