Skip to content

Build: #BBB-142 CI/CD μˆ˜μ • #36

Build: #BBB-142 CI/CD μˆ˜μ •

Build: #BBB-142 CI/CD μˆ˜μ • #36

Workflow file for this run

name: Deploy to AWS ECS on Fargate
on:
pull_request:
branches: [ "develop" ]
# types:
# - closed
workflow_dispatch:
jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: devs-spring-boot
ECS_SERVICE: devs-spring-server-service
ECS_CLUSTER: devs-cluster-be-01
ECS_TASK_DEFINITION: ./devs-spring-server-task.json
CONTAINER_NAME: spring-boot
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Restore jar
uses: actions/cache/restore@v4
with:
path: app/external-api/build/libs
key: ${{ runner.os }}-cached-jar-
restore-keys: ${{ runner.os }}-cached-jar-
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ECR_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and Push Image to Amazon ECR
uses: docker/build-push-action@v3
id: build-and-push
env:
ECR: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
with:
context: .
push: true
provenance: false
tags: ${{ env.ECR }}:${{ github.sha }}
platforms: linux/arm64
cache-from: type=registry,ref=${{ env.ECR }}:cache
cache-to: type=registry,ref=${{ env.ECR }}:cache,image-manifest=true
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ fromJSON(steps.build-and-push.outputs.metadata)['image.name'] }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true