Merge branch 'dev' #16
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: DEV - Deploy to Amazon ECS | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
AWS_REGION: ap-northeast-2 | |
ECR_REPOSITORY: few-ecr | |
ECS_SERVICE: few-ecs-service | |
ECS_CLUSTER: few-ecs-cluster | |
ECS_TASK_DEFINITION: task-definition.json | |
TASK_DEFINITION_NAME: few-ecs-task | |
CONTAINER_NAME: few-container | |
jobs: | |
build-and-push-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Cache Gradle | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: gradle | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Jooq Code Generation | |
run: | | |
./gradlew jooqCodegenAll | |
- name: Test with Gradle | |
run: | | |
./gradlew test -parallel | |
- name: Generate OpenAPI3 | |
run: | | |
./gradlew api:openapi3 -PserverUrl=https://api.fewletter.site | |
- name: Generate Swagger | |
run: | | |
./gradlew api:generateStaticSwaggerUIApi | |
- name: Build with Gradle bootBuildImage, tag, and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
run: | | |
GIT_HASH=$(git rev-parse --short HEAD) | |
./gradlew buildEcsDockerImage -PimageName=${ECR_REGISTRY}/${ECR_REPOSITORY}:latest | |
docker tag ${ECR_REGISTRY}/${ECR_REPOSITORY}:latest ${ECR_REGISTRY}/${ECR_REPOSITORY}:${GIT_HASH} | |
docker push ${ECR_REGISTRY}/${ECR_REPOSITORY} --all-tags | |
- name: Get ECR Repository image path | |
id: get-docker-image-path | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
run: | | |
GIT_HASH=$(git rev-parse --short HEAD) | |
echo ${ECR_REGISTRY}/${ECR_REPOSITORY}:${GIT_HASH} | |
echo "::set-output name=image::${ECR_REGISTRY}/${ECR_REPOSITORY}:${GIT_HASH}" | |
- name: Download task definition | |
run: | | |
aws ecs describe-task-definition --task-definition ${TASK_DEFINITION_NAME} --query taskDefinition > task-definition.json | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-definition | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: ${{ env.ECS_TASK_DEFINITION }} | |
container-name: ${{ env.CONTAINER_NAME }} | |
image: ${{ steps.get-docker-image-path.outputs.image }} | |
- name: Deploy Amazon ECS task definition | |
id: ecs-deployment | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-definition.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE }} | |
cluster: ${{ env.ECS_CLUSTER }} | |
wait-for-service-stability: true |