Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
aws-region: ${{ .env.AWS_REGION }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
actionlint .github/workflows/deploy-production.yml

Repository: MoMoGo-QuizPlatform/MoMoGo

Length of output: 480


.env.AWS_REGION 표현식을 env.AWS_REGION으로 수정하세요.

${{ .env.AWS_REGION }}는 유효하지 않은 GitHub Actions 표현식입니다. env는 워크플로 파일 최상위 env 블록에서 정의된 변수에 접근하는 컨텍스트이므로, 이 표기로 파스 오류가 사라집니다.

🧰 Tools
🪛 actionlint (1.7.12)

[error] 85-85: unexpected token "." while parsing variable access, function call, null, bool, int, float or string. expecting "IDENT", "(", "INTEGER", "FLOAT", "STRING"

(expression)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deploy-production.yml at line 85, Update the aws-region
configuration to reference the workflow environment variable with the valid
env.AWS_REGION expression, removing the leading dot from the current expression.

Source: Linters/SAST tools


- name: S3 업로드 (변경된 것만 선택적 업로드)
if: steps.filter.outputs.backend == 'true' || steps.filter.outputs.frontend == 'true'
Expand All @@ -103,12 +103,14 @@ jobs:
# ==========================================
# 4. SSM EC2 배포 실행 (변경된 부분만 선택적 재시작)
# ==========================================
- name: SSM으로 EC2 배포 트리거
- name: SSM으로 EC2 배포 트리거 (멀티 인스턴스 대응)
if: steps.filter.outputs.backend == 'true' || steps.filter.outputs.frontend == 'true'
run: |
INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=${{ env.EC2_TAG_NAME }}" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" --output text)
INSTANCE_IDS=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=momogo-app,momogo-app-2" "Name=instance-state-name,Values=running" \
--query "Reservations[*].Instances[*].InstanceId" --output text)

echo "Target EC2 Instance IDs: $INSTANCE_IDS"

# 백엔드/프론트엔드 동적 스크립트 구성
COMMANDS=()
Expand All @@ -117,31 +119,33 @@ jobs:
COMMANDS+=("aws s3 cp s3://${{ env.S3_BUCKET }}/deploy/api.jar /home/ec2-user/api.jar")
COMMANDS+=("aws s3 cp s3://${{ env.S3_BUCKET }}/deploy/realtime.jar /home/ec2-user/realtime.jar")
COMMANDS+=("aws s3 cp s3://${{ env.S3_BUCKET }}/deploy/batch.jar /home/ec2-user/batch.jar")
COMMANDS+=("sudo systemctl restart momogo-api")
COMMANDS+=("sudo systemctl restart momogo-realtime")
COMMANDS+=("sudo systemctl restart momogo-batch")
COMMANDS+=("sudo systemctl restart momogo-api || true")
COMMANDS+=("sudo systemctl restart momogo-realtime || true")
COMMANDS+=("sudo systemctl restart momogo-batch || true")
Comment on lines +122 to +124

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

배포 실패를 성공으로 처리하지 마세요.

|| true는 서비스 재시작, Nginx 재로드, 그리고 두 상태 확인 URL의 실패를 모두 성공으로 처리합니다. 배포 대상이 이전 버전으로 남아도 워크플로가 성공할 수 있습니다.

  • .github/workflows/deploy-production.yml#L122-L124: momogo-api, momogo-realtime, momogo-batch 재시작 실패를 전파하세요.
  • .github/workflows/deploy-production.yml#L131-L131: Nginx 재로드 실패를 전파하세요.
  • .github/workflows/deploy-production.yml#L151-L151: 첫 번째 URL 실패 시 두 번째 URL만 시도하고, 둘 다 실패하면 단계를 실패시키세요.
수정 예시
-            COMMANDS+=("sudo systemctl restart momogo-api || true")
-            COMMANDS+=("sudo systemctl restart momogo-realtime || true")
-            COMMANDS+=("sudo systemctl restart momogo-batch || true")
+            COMMANDS+=("sudo systemctl restart momogo-api")
+            COMMANDS+=("sudo systemctl restart momogo-realtime")
+            COMMANDS+=("sudo systemctl restart momogo-batch")
...
-            COMMANDS+=("sudo systemctl reload nginx || true")
+            COMMANDS+=("sudo systemctl reload nginx")
...
-          curl -f http://momogo.kro.kr/actuator/health || curl -f http://13.125.84.26/actuator/health || true
+          curl -f http://momogo.kro.kr/actuator/health || curl -f http://13.125.84.26/actuator/health
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COMMANDS+=("sudo systemctl restart momogo-api || true")
COMMANDS+=("sudo systemctl restart momogo-realtime || true")
COMMANDS+=("sudo systemctl restart momogo-batch || true")
COMMANDS+=("sudo systemctl restart momogo-api")
COMMANDS+=("sudo systemctl restart momogo-realtime")
COMMANDS+=("sudo systemctl restart momogo-batch")
📍 Affects 1 file
  • .github/workflows/deploy-production.yml#L122-L124 (this comment)
  • .github/workflows/deploy-production.yml#L131-L131
  • .github/workflows/deploy-production.yml#L151-L151
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deploy-production.yml around lines 122 - 124, Remove error
suppression from the deployment commands so failures propagate: update
.github/workflows/deploy-production.yml lines 122-124 for the momogo-api,
momogo-realtime, and momogo-batch restarts, and line 131 for Nginx reload. At
line 151, retain fallback from the first status URL to the second, but make the
step fail when both URL checks fail.

fi

if [ "${{ steps.filter.outputs.frontend }}" == "true" ]; then
COMMANDS+=("aws s3 cp s3://${{ env.S3_BUCKET }}/deploy/frontend-dist.tar.gz /home/ec2-user/frontend-dist.tar.gz")
COMMANDS+=("sudo mkdir -p /usr/share/nginx/html/momogo")
COMMANDS+=("sudo tar -xzvf /home/ec2-user/frontend-dist.tar.gz -C /usr/share/nginx/html/momogo/")
COMMANDS+=("sudo systemctl reload nginx")
COMMANDS+=("sudo systemctl reload nginx || true")
fi

# JSON 배열 포맷팅 후 SSM 명령 전달
JSON_COMMANDS=$(jq -n --argjson cmds "$(printf '%s\n' "${COMMANDS[@]}" | jq -R . | jq -s .)" '$cmds')

FIRST_INSTANCE=$(echo $INSTANCE_IDS | awk '{print $1}')

COMMAND_ID=$(aws ssm send-command \
--instance-ids "$INSTANCE_ID" \
--instance-ids $INSTANCE_IDS \
--document-name "AWS-RunShellScript" \
--parameters "{\"commands\": $JSON_COMMANDS}" \
--query "Command.CommandId" --output text)

aws ssm wait command-executed --command-id "$COMMAND_ID" --instance-id "$INSTANCE_ID"
aws ssm wait command-executed --command-id "$COMMAND_ID" --instance-id "$FIRST_INSTANCE"
Comment on lines +137 to +145

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

모든 대상 인스턴스의 SSM 완료를 대기하세요.

현재 단계는 첫 번째 인스턴스만 대기합니다. 첫 번째 인스턴스가 성공하면 다른 인스턴스가 아직 실행 중이거나 실패했어도 워크플로가 다음 단계로 진행합니다.

INSTANCE_IDS 대상의 command-executed 상태를 대기하세요.

수정 예시
-          FIRST_INSTANCE=$(echo $INSTANCE_IDS | awk '{print $1}')
-
           COMMAND_ID=$(aws ssm send-command \
             --instance-ids $INSTANCE_IDS \
             --document-name "AWS-RunShellScript" \
             --parameters "{\"commands\": $JSON_COMMANDS}" \
             --query "Command.CommandId" --output text)
 
-          aws ssm wait command-executed --command-id "$COMMAND_ID" --instance-id "$FIRST_INSTANCE"
+          for INSTANCE_ID in $INSTANCE_IDS; do
+            aws ssm wait command-executed \
+              --command-id "$COMMAND_ID" \
+              --instance-id "$INSTANCE_ID"
+          done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FIRST_INSTANCE=$(echo $INSTANCE_IDS | awk '{print $1}')
COMMAND_ID=$(aws ssm send-command \
--instance-ids "$INSTANCE_ID" \
--instance-ids $INSTANCE_IDS \
--document-name "AWS-RunShellScript" \
--parameters "{\"commands\": $JSON_COMMANDS}" \
--query "Command.CommandId" --output text)
aws ssm wait command-executed --command-id "$COMMAND_ID" --instance-id "$INSTANCE_ID"
aws ssm wait command-executed --command-id "$COMMAND_ID" --instance-id "$FIRST_INSTANCE"
COMMAND_ID=$(aws ssm send-command \
--instance-ids $INSTANCE_IDS \
--document-name "AWS-RunShellScript" \
--parameters "{\"commands\": $JSON_COMMANDS}" \
--query "Command.CommandId" --output text)
for INSTANCE_ID in $INSTANCE_IDS; do
aws ssm wait command-executed \
--command-id "$COMMAND_ID" \
--instance-id "$INSTANCE_ID"
done
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deploy-production.yml around lines 137 - 145, Update the
SSM wait logic after `COMMAND_ID` is created to wait for `command-executed` on
every instance in `INSTANCE_IDS`, not only `FIRST_INSTANCE`. Iterate over all
target instance IDs and preserve the existing command ID and AWS CLI waiter
usage for each one.


- name: 배포 결과 확인
if: steps.filter.outputs.backend == 'true'
run: |
sleep 15
curl -f http://${{ secrets.ALB_DNS_NAME }}/actuator/health
curl -f http://momogo.kro.kr/actuator/health || curl -f http://13.125.84.26/actuator/health || true