[dev -> main] 2025.10.13 05:07 #9
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: CI - Build & Push Docker Image to ECR | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| types: | |
| - closed | |
| jobs: | |
| build-and-push: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| ECR_REPOSITORY: difflens-spring | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Build Spring Boot Jar | |
| run: ./gradlew clean build -x test | |
| - name: Build Docker Image | |
| run: docker build -t ${{ env.ECR_REPOSITORY }}:latest . | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v2 | |
| 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 | |
| id: ecr-login | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| - name: Tag Docker Image for ECR | |
| run: | | |
| docker tag ${{ env.ECR_REPOSITORY }}:latest \ | |
| ${{ steps.ecr-login.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest | |
| - name: Push Docker Image to ECR | |
| run: | | |
| docker push ${{ steps.ecr-login.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest |