Merge pull request #1 from enjoy-hack/CD #17
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: CD for main | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to deploy from' | |
| required: true | |
| default: 'develop' | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-northeast-2 | |
| - name: Login to Amazon ECR | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build and push Docker image (single arch) | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| platforms: linux/amd64 # ⚡ 멀티 플랫폼 제거 → 빌드 속도 2~3배 향상 | |
| push: true | |
| tags: 867344478016.dkr.ecr.ap-northeast-2.amazonaws.com/enjoy-app:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: SSH into EC2 and deploy | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ec2-user | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| timeout: 300s | |
| script: | | |
| cd /home/ec2-user/back | |
| docker-compose down | |
| docker pull 867344478016.dkr.ecr.ap-northeast-2.amazonaws.com/enjoy-app:latest | |
| docker-compose up -d |