diff --git a/.github/workflows/rankit-multiaz-cicd.yml b/.github/workflows/rankit-multiaz-cicd.yml index 0dc5b3e..ae24846 100644 --- a/.github/workflows/rankit-multiaz-cicd.yml +++ b/.github/workflows/rankit-multiaz-cicd.yml @@ -16,7 +16,7 @@ jobs: run: | sudo apt-get update sudo apt-get install awscli -y - + # 2. AWS 자격 증명 설정 - name: Configure AWS credentials env: @@ -25,7 +25,7 @@ jobs: run: | aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set region ap-northeast-2 # 서울 AWS 리전을 설정 + aws configure set region ap-northeast-2 # 3. Bastion 호스트에 접속하여 EC2-A에 docker-compose 실행 - name: Deploy to EC2-A via Bastion Host @@ -37,10 +37,11 @@ jobs: chmod 600 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@$BASTION_HOST << 'EOF' ssh -o StrictHostKeyChecking=no -i /home/ec2-user/my-key.pem ec2-user@${{ secrets.EC2_A_IP }} << 'INNER_EOF' - if [ $(docker-compose ps -q app | xargs -r docker inspect -f '{{.State.Running}}') == 'true' ]; then + if [ "$(docker-compose ps -q app | xargs -r docker inspect -f '{{.State.Running}}')" = 'true' ]; then docker-compose stop; fi - sleep 3 && docker-compose up -d --pull always + sleep 3 + docker-compose up -d --pull always INNER_EOF EOF rm private_key.pem # 사용 후 PEM 파일 삭제 @@ -57,18 +58,18 @@ jobs: --query "TargetHealthDescriptions[?Target.Id=='${{ secrets.EC2_A_ID }}'].TargetHealth.State" \ --output text) - if [ "$HEALTH_STATUS" == "healthy" ]; then + if [ "$HEALTH_STATUS" = "healthy" ]; then echo "EC2-A is healthy." break else echo "Waiting for EC2-A to become healthy..." - sleep 10 # 10초 대기 후 상태 확인 - ATTEMPT=$((ATTEMPT + 1)) # 시도 횟수 증가 + sleep 10 + ATTEMPT=$((ATTEMPT + 1)) fi if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then echo "EC2-A is not healthy after $MAX_ATTEMPTS attempts. Exiting." - exit 1 # 파이프라인 종료 + exit 1 fi done @@ -82,14 +83,15 @@ jobs: chmod 600 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem ec2-user@$BASTION_HOST << 'EOF' ssh -o StrictHostKeyChecking=no -i /home/ec2-user/my-key.pem ec2-user@${{ secrets.EC2_C_IP }} << 'INNER_EOF' - if [ $(docker-compose ps -q app | xargs -r docker inspect -f '{{.State.Running}}') == 'true' ]; then + if [ "$(docker-compose ps -q app | xargs -r docker inspect -f '{{.State.Running}}')" = 'true' ]; then docker-compose stop; fi - sleep 3 && docker-compose up -d --pull always + sleep 3 + docker-compose up -d --pull always INNER_EOF EOF rm private_key.pem # 사용 후 PEM 파일 삭제 - + # 6. EC2-C alb 연결상태 확인 - name: Register EC2-C to Target Group run: | @@ -102,17 +104,17 @@ jobs: --query "TargetHealthDescriptions[?Target.Id=='${{ secrets.EC2_C_ID }}'].TargetHealth.State" \ --output text) - if [ "$HEALTH_STATUS" == "healthy" ]; then + if [ "$HEALTH_STATUS" = "healthy" ]; then echo "EC2-C is healthy." break else echo "Waiting for EC2-C to become healthy..." - sleep 10 # 10초 대기 후 상태 확인 - ATTEMPT=$((ATTEMPT + 1)) # 시도 횟수 증가 + sleep 10 + ATTEMPT=$((ATTEMPT + 1)) fi if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then echo "EC2-C is not healthy after $MAX_ATTEMPTS attempts. Exiting." - exit 1 # 파이프라인 종료 + exit 1 fi done