Merge pull request #17 from mingoo36/master #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: Build and Push to ECR | |
on: | |
push: | |
branches: | |
- master # master 브랜치에 푸시될 때 실행 | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. GitHub Repository 코드 가져오기 | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# 2. AWS ECR 로그인 | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# 3. Docker 이미지 빌드 및 푸시 | |
- name: Build and Push Docker Image | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} # AWS 리전 | |
ECR_REGISTRY: 340752825399.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com # 레지스트리 URI | |
ECR_REPOSITORY: mingoo-repo # ECR 리포지토리 이름 | |
IMAGE_TAG: ${{ github.sha }} # Git 커밋 SHA를 이미지 태그로 사용 | |
run: | | |
# Docker 이미지 빌드 | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
# Docker 이미지를 ECR에 푸시 | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |