Skip to content

Conversation

@jsoonworld
Copy link
Member

📄 Work Description

GitHub Actions를 이용한 스테이징 서버 무중단 배포(Blue-Green) 워크플로우를 개선했습니다.

  • CD 스크립트 오류 처리 강화: 배포 과정 중 특정 명령어(e.g. docker run)가 실패해도 워크플로우가 성공으로 표시되던 문제를 해결했습니다.
  • 포트 전환 로직 안정화: 현재 실행 중인 컨테이너를 탐지하고 다음 배포 포트를 결정하는 로직을 더 안정적인 방식으로 변경했습니다.
  • 로그 및 정리 로직 개선: 최초 배포 시나리오를 고려하여, 불필요한 오류 로그가 발생하지 않도록 이전 컨테이너 삭제 로직을 수정했습니다

💬 To Reviewers

이번 PR은 배포 안정성에 초점을 맞추었습니다. 아래 부분들을 중점적으로 확인해 주시면 좋겠습니다.

  1. set -e 추가 (스크립트 최상단)
  • 이 한 줄의 추가로 이제 스크립트의 어느 한 부분이라도 실패하면 전체 배포가 중단되고 Action이 '실패'로 표시됩니다. 이는 잠재적인 배포 사고를 막는 가장 중요한 변경점입니다.
  1. Blue/Green 포트 결정 로직 변경
  • 기존에는 docker ps 결과의 문자열을 grep과 awk로 파싱하여 불안정했습니다.

  • 이를 docker ps -q --filter "publish=8080" 와 같이 docker의 필터 기능을 사용하도록 변경하여 명확성과 안정성을 높였습니다. OLD_CONTAINER_NAME과 NEW_CONTAINER_NAME 변수를 도입하여 이후의 docker run, docker rm 명령어의 가독성과 안정성을 확보했습니다.

  1. 이전 컨테이너 삭제 로직 (### 6.)
  • docker ps -aq --filter "name=${OLD_CONTAINER_NAME}" 명령으로 삭제할 대상 컨테이너가 실제로 존재하는지 먼저 확인하도록 수정했습니다.

  • 이를 통해 최초 배포 시(삭제할 구버전 컨테이너가 없는 경우) No such container 오류가 발생하지 않습니다.

@jsoonworld jsoonworld requested a review from Copilot July 3, 2025 03:38
@jsoonworld jsoonworld self-assigned this Jul 3, 2025
@jsoonworld jsoonworld added ♻️ refactor 코드 리팩토링 ex) 형식변경 🦊장순🦊 labels Jul 3, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR strengthens the staging Blue-Green deployment workflow by enforcing strict error handling, stabilizing the port-detection logic using Docker filters, and preventing unnecessary failures during the initial cleanup step.

  • Adds set -e to abort on any command failure
  • Replaces grep/awk parsing with Docker’s --filter for port detection and introduces named container variables
  • Updates cleanup logic to check for the existence of old containers before attempting removal
Comments suppressed due to low confidence (4)

.github/workflows/DOCKER-CD-STAGING.yml:67

  • [nitpick] Remove the extra blank line following set -e to keep the script concise and maintain consistent formatting.
            set -e

.github/workflows/DOCKER-CD-STAGING.yml:78

  • [nitpick] Consider renaming IS_BLUE_RUNNING to something like BLUE_CONTAINER_ID or BLUE_RUNNING_ID since it holds a container ID, which improves readability of the logic.
            IS_BLUE_RUNNING=$(docker ps -q --filter "name=${APP_NAME}" --filter "publish=8080")

.github/workflows/DOCKER-CD-STAGING.yml:91

  • Add automated tests or a dry-run mode for the first-deploy and port-switch branches to ensure the new error-handling and port-detection logic works as intended and prevent regressions.
            if [ -z "$IS_BLUE_RUNNING" ] && [ -z "$(docker ps -q --filter "name=${APP_NAME}" --filter "publish=8081")" ]; then

.github/workflows/DOCKER-CD-STAGING.yml:100

  • [nitpick] Add a brief comment above the NEW_CONTAINER_NAME and OLD_CONTAINER_NAME definitions to explain their roles in the Blue-Green swap, enhancing maintainability.
            NEW_CONTAINER_NAME="${APP_NAME}-${NEW_PORT}"

@jsoonworld jsoonworld merged commit 90b191e into develop Jul 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ refactor 코드 리팩토링 ex) 형식변경 size/M 🦊장순🦊

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants