(#73) OpenAPI 계약 생성 기반 추가 #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Backend Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| env: | |
| IMAGE_NAME: git-ranker | |
| jobs: | |
| docker: | |
| name: Build & Push Docker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha,prefix= | |
| type=semver,pattern={{version}} | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| name: Deploy to Production | |
| runs-on: ubuntu-latest | |
| needs: docker | |
| if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| echo "==========================================" | |
| echo "Backend Deployment Started" | |
| echo "Time: $(date)" | |
| echo "==========================================" | |
| cd ${{ secrets.DEPLOY_PATH }} | |
| echo "[1/5] Pulling latest image..." | |
| docker compose pull git-ranker-api | |
| echo "[2/5] Restarting container..." | |
| docker compose up -d --no-deps --force-recreate git-ranker-api | |
| echo "[3/5] Waiting for Docker health status..." | |
| for i in {1..12}; do | |
| HEALTH_STATUS=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}unknown{{end}}' git-ranker-api 2>/dev/null || echo "missing") | |
| echo "Attempt $i/12 - container health: $HEALTH_STATUS" | |
| if [ "$HEALTH_STATUS" = "healthy" ]; then | |
| break | |
| fi | |
| if [ "$HEALTH_STATUS" = "unhealthy" ] || [ "$i" -eq 12 ]; then | |
| echo "Container health check failed." | |
| docker logs --tail 200 git-ranker-api || true | |
| exit 1 | |
| fi | |
| sleep 10 | |
| done | |
| echo "[4/5] Verifying actuator health endpoint..." | |
| HEALTH_URL="http://127.0.0.1:9090/actuator/health" | |
| RESPONSE=$(curl -sS --connect-timeout 5 --max-time 10 -w '\n%{http_code}' "$HEALTH_URL" || true) | |
| HTTP_STATUS=$(printf '%s' "$RESPONSE" | tail -n1) | |
| RESPONSE_BODY=$(printf '%s' "$RESPONSE" | sed '$d') | |
| if [ "$HTTP_STATUS" != "200" ] || ! echo "$RESPONSE_BODY" | grep -Eq '"status"[[:space:]]*:[[:space:]]*"UP"'; then | |
| echo "Actuator health check failed. HTTP=$HTTP_STATUS, body=$RESPONSE_BODY" | |
| docker logs --tail 200 git-ranker-api || true | |
| exit 1 | |
| fi | |
| echo "[5/5] Cleaning up old images..." | |
| docker image prune -f | |
| echo "==========================================" | |
| echo "Backend Deployment Completed!" | |
| echo "==========================================" |