Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 36 additions & 4 deletions .github/workflows/deploy-to-prod-ec2-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ name: Deploy to Prod (EC2 Docker Compose via GHCR)
on:
push:
branches: [ main ]
workflow_dispatch: {}
workflow_dispatch:
inputs:
deploy_mode:
description: 앱을 배포하거나 이전 검증을 위해 이미지만 빌드·업로드합니다
type: choice
required: true
default: full
options:
- full
- image-only

concurrency:
group: saerok-prod-deploy
cancel-in-progress: false

jobs:
deploy:
if: ${{ github.event_name == 'workflow_dispatch' || vars.PROD_ARM64_AUTODEPLOY == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
environment: prod
env:
DEPLOY_MODE: ${{ inputs.deploy_mode || 'full' }}

steps:
- name: Checkout
Expand All @@ -21,6 +37,11 @@ jobs:
id: normalize
run: echo "image_repo=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"

- name: Set up ARM64 emulation
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Set up Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -37,22 +58,25 @@ jobs:
with:
images: ${{ steps.normalize.outputs.image_repo }}
tags: |
type=raw,value=prod-latest
type=sha,format=long,prefix=prod-
type=raw,value=prod-latest,enable=${{ env.DEPLOY_MODE == 'full' }}
type=sha,format=long,prefix=prod-,enable=${{ env.DEPLOY_MODE == 'full' }}
type=raw,value=migration-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }},enable=${{ env.DEPLOY_MODE == 'image-only' }}

- name: Build & Push (BE image)
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache
cache-to: type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache,mode=max

- name: Copy compose to EC2
if: ${{ env.DEPLOY_MODE == 'full' }}
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
Expand All @@ -63,6 +87,7 @@ jobs:
strip_components: 1

- name: Deploy on EC2
if: ${{ env.DEPLOY_MODE == 'full' }}
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.EC2_HOST }}
Expand Down Expand Up @@ -120,16 +145,22 @@ jobs:
docker pull "$IMAGE_REF"

# 이번 릴리스 digest를 사용해 재기동
docker compose --env-file "$ENV_FILE" -f docker-compose.prod.yml up -d --force-recreate --quiet-pull app
docker compose --env-file "$ENV_FILE" -p saerok-prod -f docker-compose.yml -f docker-compose.prod.yml up -d --force-recreate --quiet-pull app

echo "Waiting for BE /health..."
healthy=false
for i in {1..40}; do
if curl -fsS --max-time 2 http://127.0.0.1:8080/health >/dev/null; then
echo "✅ BE is healthy"
healthy=true
break
fi
echo "⏳ ($i/40)"; sleep 3
done
if [ "$healthy" != true ]; then
echo 'BE health check timed out' >&2
exit 1
fi

docker image prune -af --filter "until=168h" || true
docker builder prune -af --filter "until=168h" || true
Expand All @@ -139,6 +170,7 @@ jobs:
run: |
{
echo "## Prod deploy"
echo "- Mode: $DEPLOY_MODE"
echo "- Image: ${{ steps.normalize.outputs.image_repo }}@${{ steps.build.outputs.digest }}"
echo "- Commit: ${{ github.sha }}"
echo "- Actor: ${{ github.actor }}"
Expand Down
88 changes: 0 additions & 88 deletions .github/workflows/deploy-to-prod-ec2.yml

This file was deleted.

Loading