-
Notifications
You must be signed in to change notification settings - Fork 2
94 lines (80 loc) · 3.21 KB
/
deploy-dev-ecs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: DEV - Deploy to Amazon ECS
on:
push:
branches:
- develop
workflow_dispatch:
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: three-days/be-api-develop
ECS_SERVICE: three-days-be-api-develop
ECS_CLUSTER: three-days-cluster-develop
ECS_TASK_DEFINITION: task-definition.json
CONTAINER_NAME: three-days-be-api-develop
jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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: Integration Test with Gradle
run: |
docker-compose -f resources/local-develop-environment/docker-compose.yml up -d
sleep 20
./gradlew :data:flywayClean :data:flywayMigrate
export SPRING_PROFILES_ACTIVE=integration-test
./gradlew integrationTest
- name: Create Swagger API Spec
run: |
./gradlew :app:openapi3
- 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 :app:buildDockerImage -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 ${CONTAINER_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