Merge pull request #23 from POPCONG/develop #5
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: Release Deploy | ||
| on: | ||
| push: | ||
| branches: ["release"] | ||
| workflow_dispatch: {} | ||
| env: | ||
| AWS_REGION: us-west-2 | ||
| ACCOUNT_ID: 590184104064 | ||
| ECR_REPOSITORY: popcong-server | ||
| REGISTRY: ${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com | ||
| IMAGE_TAG: ${{ github.sha }} | ||
| concurrency: | ||
| group: release-deploy | ||
| cancel-in-progress: true | ||
| jobs: | ||
| build-and-push: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
| - name: Login to Amazon ECR | ||
| uses: aws-actions/amazon-ecr-login@v2 | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
| - name: Build & Push (linux/amd64) | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| platforms: linux/amd64 | ||
| push: true | ||
| context: . | ||
| file: ./Dockerfile | ||
| tags: | | ||
| ${{ env.REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | ||
| ${{ env.REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | ||
| deploy: | ||
| needs: build-and-push | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - name: Connect & Deploy on EC2 | ||
| uses: appleboy/[email protected] | ||
| with: | ||
| host: ${{ secrets.EC2_HOST }} | ||
| username: ${{ secrets.EC2_USER }} | ||
| key: ${{ secrets.EC2_SSH_KEY }} | ||
| script: | | ||
| set -euo pipefail | ||
| AWS_REGION="${{ env.AWS_REGION }}" | ||
| ACCOUNT_ID="${{ env.ACCOUNT_ID }}" | ||
| REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" | ||
| echo "[EC2] ECR 로그인" | ||
| aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$REGISTRY" | ||
| echo "[EC2] 디렉토리 이동" | ||
| cd ~/popcong | ||
| echo "[EC2] 최신 이미지 Pull" | ||
| docker compose pull | ||
| echo "[EC2] 재기동" | ||
| docker compose up -d --remove-orphans | ||
| echo "[EC2] 상태 확인" | ||
| docker compose ps | ||
| docker ps | ||