main push builds the runtime image (linux/amd64), pushes it to ECR plagiarism-api:<sha> and runs SSM Deploy-plagiarism, which swaps the container and rolls back if it is not healthy. Python and pip versions are pinned to the King production image so the joblib model keeps loading. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
68 lines
2.5 KiB
YAML
68 lines
2.5 KiB
YAML
# main push → 이미지 빌드(linux/amd64) → ECR plagiarism-api:<sha> → SSM Deploy-plagiarism → o2o-platform-plagiarism
|
|
# 서버의 /srv/plagiarism/deploy.sh가 교체 후 health를 보고, 실패하면 직전 이미지로 되돌린다.
|
|
# 인프라 정의: o2o-aws infra/envs/prod/plagiarism.tf (역할·문서·ECR), infra/server/plagiarism (서버 스크립트)
|
|
# 같은 sha 재배포·롤백: Actions에서 이 워크플로를 main에 수동 실행(이미지가 이미 있으면 빌드를 건너뛴다).
|
|
name: deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
id-token: write
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: deploy
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
AWS_REGION: ap-northeast-2
|
|
ROLE_ARN: arn:aws:iam::277206319065:role/o2o-github-deploy-plagiarism
|
|
ECR_REPO: plagiarism-api
|
|
INSTANCE_ID: i-03733fc4b9ce2a1e7
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 40
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: aws-actions/configure-aws-credentials@v4
|
|
with:
|
|
role-to-assume: ${{ env.ROLE_ARN }}
|
|
aws-region: ${{ env.AWS_REGION }}
|
|
|
|
- id: ecr
|
|
uses: aws-actions/amazon-ecr-login@v2
|
|
|
|
- name: Build and push (skip if the tag exists)
|
|
env:
|
|
IMAGE: ${{ steps.ecr.outputs.registry }}/${{ env.ECR_REPO }}:${{ github.sha }}
|
|
run: |
|
|
if aws ecr describe-images --repository-name "$ECR_REPO" --image-ids imageTag="$GITHUB_SHA" >/dev/null 2>&1; then
|
|
echo "image exists, skip build: $IMAGE"
|
|
exit 0
|
|
fi
|
|
docker build --platform linux/amd64 --target runtime -t "$IMAGE" .
|
|
docker push "$IMAGE"
|
|
|
|
- name: Deploy via SSM
|
|
run: |
|
|
cid=$(aws ssm send-command --instance-ids "$INSTANCE_ID" --document-name Deploy-plagiarism \
|
|
--parameters Tag="$GITHUB_SHA" --query Command.CommandId --output text)
|
|
echo "command $cid"
|
|
for _ in $(seq 1 120); do
|
|
sleep 10
|
|
status=$(aws ssm get-command-invocation --command-id "$cid" --instance-id "$INSTANCE_ID" \
|
|
--query Status --output text 2>/dev/null || echo Pending)
|
|
case "$status" in Pending|InProgress|Delayed) continue ;; esac
|
|
break
|
|
done
|
|
aws ssm get-command-invocation --command-id "$cid" --instance-id "$INSTANCE_ID" \
|
|
--query '[StandardOutputContent,StandardErrorContent]' --output text
|
|
echo "status: $status"
|
|
[ "$status" = Success ]
|