CD - Deploy Docker Image to EC2 #21
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 - Deploy Docker Image to EC2 | |
| on: | |
| workflow_run: | |
| workflows: ["CI - Build & Push Docker Image to ECR"] | |
| types: | |
| - completed | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| ECR_REPOSITORY: difflens-spring | |
| IMAGE_TAG: latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to EC2 via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_PUBLIC_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| port: 22 | |
| script: | | |
| AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }} | |
| aws ecr get-login-password --region ${{ env.AWS_REGION }} \ | |
| | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com | |
| docker pull $AWS_ACCOUNT_ID.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
| docker compose -f /home/ubuntu/docker-compose.yml down | |
| docker compose -f /home/ubuntu/docker-compose.yml up -d |