Skip to content

Commit

Permalink
fix: 테스트 오류 수정 및 안정성 개선
Browse files Browse the repository at this point in the history
- 환경 변수 지원 추가:
  - `ROOT_PATH`, `HEALTH_CHECK_MAX_RETRIES`, `HEALTH_CHECK_INTERVAL`을 환경 변수로 설정 가능하도록 수정.

- 배포 인자 검증 로직 강화:
  - 환경 변수 파일 존재 여부 및 읽기 권한 확인 추가.

- AWS ECR 인증 과정 개선:
  - AWS 로그인 실패 시 에러 메시지를 출력하고 스크립트를 종료하도록 수정.
  - 인증 성공 여부를 명확히 로그로 출력.

- Docker 이미지 풀링 및 배포 과정 안정화:
  - 이미지 풀링 실패 시 에러 메시지를 출력하고 스크립트를 종료하도록 처리.
  - Blue/Green 배포 로직 메시지를 가독성 높게 수정.

테스트를 통해 발견된 문제를 해결하고, 스크립트의 안정성과 유연성을 강화했습니다.
  • Loading branch information
do0ori committed Dec 22, 2024
1 parent 113d67b commit 74cff2c
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions .github/script/run_backend.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

# Constants
readonly ROOT_PATH="/home/ubuntu/actions-runner/_work/dangdang-walk/dangdang-walk/backend/server"
readonly HEALTH_CHECK_MAX_RETRIES=10
readonly HEALTH_CHECK_INTERVAL=3
readonly ROOT_PATH=${ROOT_PATH:-"/home/ubuntu/actions-runner/_work/dangdang-walk/dangdang-walk/backend/server"}
readonly HEALTH_CHECK_MAX_RETRIES=${HEALTH_CHECK_MAX_RETRIES:-10}
readonly HEALTH_CHECK_INTERVAL=${HEALTH_CHECK_INTERVAL:-3}
readonly CONTAINER_INTERNAL_PORT=3031
readonly BLUE_EXTERNAL_PORT=3032
readonly GREEN_EXTERNAL_PORT=3031
Expand Down Expand Up @@ -34,13 +34,36 @@ validate_deployment_args() {
fi
done

# Check if ENV file exists and has read permissions
if [ ! -f "$ENV_FILE_PATH" ]; then
log_error "Environment file not found: $ENV_FILE_PATH"
exit 1
fi

if [ ! -r "$ENV_FILE_PATH" ]; then
log_error "Environment file is not readable: $ENV_FILE_PATH"
exit 1
fi

log_info "Deployment arguments validated."
}

# AWS ECR Authentication
authenticate_to_ecr() {
log_info "Authenticating with AWS ECR..."
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin "$REPO"

local aws_login_password
if ! aws_login_password=$(aws ecr get-login-password --region ap-northeast-2); then
log_error "Failed to get AWS ECR login password"
exit 1
fi

if ! echo "$aws_login_password" | docker login --username AWS --password-stdin "$REPO"; then
log_error "Failed to authenticate with AWS ECR"
exit 1
fi

log_success "Successfully authenticated with AWS ECR"
}

# Docker Container Management
Expand Down Expand Up @@ -87,9 +110,16 @@ verify_container_health() {
perform_deployment() {
local container_name=$1
local port=$2

log_info "Starting deployment for $container_name on port $port..."

cleanup_container "$container_name"
docker pull "$CONTAINER_IMAGE"

if ! docker pull "$CONTAINER_IMAGE"; then
log_error "Failed to pull container image: $CONTAINER_IMAGE"
exit 1
fi

deploy_new_container "$container_name" "$port"
}

Expand Down Expand Up @@ -128,10 +158,10 @@ main() {
GREEN_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' dangdang-api-green 2>/dev/null)

if [ "$BLUE_CONTAINER_STATUS" == "running" ]; then
log_info "Active: Blue container - Switching to Green deployment..."
log_info "Blue container is running - Switching to Green container..."
activate_green_deployment
elif [ "$GREEN_CONTAINER_STATUS" == "running" ]; then
log_info "Active: Green container - Switching to Blue deployment..."
log_info "Green container is running - Switching to Blue container..."
activate_blue_deployment
else
log_info "No active deployment found - Initiating Blue deployment..."
Expand Down

0 comments on commit 74cff2c

Please sign in to comment.