Skip to content

[Chore/#445] Swagger 생성 Task 개선 (#446) #81

[Chore/#445] Swagger 생성 Task 개선 (#446)

[Chore/#445] Swagger 생성 Task 개선 (#446) #81

Workflow file for this run

name: DEV - Deploy to Amazon ECS DEV
on:
push:
branches:
- dev
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 18
uses: actions/setup-java@v3
with:
java-version: '18'
distribution: 'temurin'
cache: gradle
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_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: Generate OpenAPI3
run: |
./gradlew api:openapi3 -PserverUrl=https://api.fewletter.shop
- name: Generate Swagger
run: |
./gradlew api:generateStaticSwaggerUI
- 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 buildPinpointEcsDockerImageDev -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