diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7068ebf --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,67 @@ +# main push → 이미지 빌드(linux/amd64) → ECR plagiarism-api: → 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 ] diff --git a/Dockerfile b/Dockerfile index 28529dc..1401648 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM python:3.13-slim AS base +# 3.13.2: King 서버 운영 이미지와 같은 Python (constraints.txt와 함께 joblib 모델 호환 유지) +FROM python:3.13.2-slim AS base WORKDIR /app @@ -14,8 +15,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* -COPY requirements.txt . -RUN pip install -r requirements.txt +COPY requirements.txt constraints.txt ./ +RUN pip install -r requirements.txt -c constraints.txt COPY app ./app COPY data ./data diff --git a/constraints.txt b/constraints.txt new file mode 100644 index 0000000..14d45ee --- /dev/null +++ b/constraints.txt @@ -0,0 +1,47 @@ +# King 서버 운영 이미지(2026-10-21 빌드, 커밋 03d500d)의 pip freeze. joblib 모델(scikit-learn) 호환을 위해 이 버전으로 고정한다. +# 버전을 올릴 때는 AI 의심도 모델을 같은 버전으로 다시 저장하고 킹/AWS 점수 비교를 다시 한다. +annotated-doc==0.0.5 +annotated-types==0.8.0 +anyio==4.14.2 +certifi==2026.7.22 +click==8.4.2 +datasketch==2.0.0 +et_xmlfile==2.0.0 +fastapi==0.141.1 +h11==0.16.0 +httpcore==1.0.9 +httpcore2==2.12.0 +httptools==0.8.0 +httpx==0.28.1 +httpx2==2.12.0 +idna==3.19 +jiter==0.16.0 +joblib==1.5.3 +kiwipiepy==0.23.2 +kiwipiepy_model==0.23.0 +lxml==6.1.2 +narwhals==2.24.0 +numpy==2.5.2 +openai==3.3.1 +openpyxl==3.1.5 +pydantic==2.13.4 +pydantic-settings==2.15.0 +pydantic_core==2.46.4 +pypdf==6.16.1 +python-docx==1.2.0 +python-dotenv==1.2.3 +python-multipart==0.0.32 +PyYAML==6.0.3 +scikit-learn==1.9.0 +scipy==1.18.0 +sniffio==1.3.1 +starlette==1.6.0 +threadpoolctl==3.6.0 +tqdm==4.70.0 +truststore==0.10.4 +typing-inspection==0.4.4 +typing_extensions==4.16.0 +uvicorn==0.52.4 +uvloop==0.22.1 +watchfiles==1.2.0 +websockets==17.0.1