Hotfix : AWS ECR 로그인 방식 변경 #3
This file contains 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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- 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 | |
run: | | |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REPOSITORY }} | |
- name: Build and push Docker image | |
id: build-image | |
run: | | |
IMAGE_TAG=$(date +%Y%m%d%H%M) | |
docker build -t ${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG . | |
docker tag ${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG ${{ secrets.ECR_REPOSITORY }}:latest | |
docker push ${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG | |
docker push ${{ secrets.ECR_REPOSITORY }}:latest | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
- name: Deploy to EC2 | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_INSTANCE_IP }} << 'EOF' | |
docker pull ${{ secrets.ECR_REPOSITORY }}:latest | |
docker-compose down | |
docker-compose up -d | |
EOF | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} |