-
Notifications
You must be signed in to change notification settings - Fork 3
187 lines (157 loc) · 7.16 KB
/
CICD.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: CICD
on:
push:
branches:
- main
env:
# Setting
REACT_ENV: ${{ secrets.REACT_ENV }}
CHATBOT_ENV: ${{ secrets.CHATBOT_ENV }}
SPRINGBOOT_ENV: ${{ secrets.SPRINGBOOT_ENV }}
APPLICATION_YML: ${{ secrets.APPLICAION_YML }}
# ECR
AWS_REGION: us-east-1
ECR_REGISTRY: 717279725295.dkr.ecr.us-east-1.amazonaws.com
REACT_ECR_REPOSITORY: openlawyer/react
CHATBOT_ECR_REPOSITORY: openlawyer/chatbot
SPRINGBOOT_ECR_REPOSITORY: openlawyer/springboot
IMAGE_TAG: latest
# ECS
ECS_CLUSTER: OpenLawyer-cicd-cluster
REACT_ECS_TASK_DEFINITION: OpenLawyer-task-react
CHATBOT_ECS_TASK_DEFINITION: OpenLawyer-task-chatbot
SPRINGBOOT_ECS_TASK_DEFINITION: OpenLawyer-task-springboot
REACT_CONTAINER_NAME: react-container
CHATBOT_CONTAINER_NAME: chatbot-container
SPRINGBOOT_CONTAINER_NAME: springboot-container
REACT_ECS_SERVICE: react-service
CHATBOT_ECS_SERVICE: chatbot-service
SPRINGBOOT_ECS_SERVICE: springboot-service
jobs:
cd-springboot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
if: contains(github.ref, 'main')
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: springboot-app 경로의 env 파일 생성
working-directory: springboot-app
run: |
echo "${{ env.SPRINGBOOT_ENV }}" > .env
shell: bash
- name: springboot-app 경로의 application.yml 파일 생성
working-directory: springboot-app/src/main/resources
run: |
echo "${{ env.APPLICATION_YML }}" > application.yml
shell: bash
- name: springboot-app 프로젝트 빌드 -> 도커파일 생성
working-directory: springboot-app
run: docker build -t ${{ env.SPRINGBOOT_ECR_REPOSITORY }} .
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Amazon ECR Private 로그인
uses: aws-actions/amazon-ecr-login@v2
- name: Tag and push Spring Boot Docker image
run: |
docker tag ${{ env.SPRINGBOOT_ECR_REPOSITORY }}:latest ${{ env.ECR_REGISTRY }}/${{ env.SPRINGBOOT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker push ${{ env.ECR_REGISTRY }}/${{ env.SPRINGBOOT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: 최신 Springboot 태스크 정의 가져오기
id: get-task-latest-springboot
run: |
aws ecs describe-task-definition --task-definition ${{ env.SPRINGBOOT_ECS_TASK_DEFINITION }} --query taskDefinition > ${{ env.SPRINGBOOT_ECS_TASK_DEFINITION }}.json
cat ${{ env.SPRINGBOOT_ECS_TASK_DEFINITION }}.json
echo "::set-output name=task-def-file::${{ env.SPRINGBOOT_ECS_TASK_DEFINITION }}.json"
- name: Amazon ECS 태스크 정의 배포 (Springboot)
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.get-task-latest-springboot.outputs.task-def-file }}
service: ${{ env.SPRINGBOOT_ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
cd-react:
runs-on: ubuntu-latest
steps:
- name: Checkout code
if: contains(github.ref, 'main')
uses: actions/checkout@v2
- name: react-app 경로의 env 파일 생성
working-directory: react-app
run: |
echo "${{ env.REACT_ENV }}" > .env
shell: bash
- name: react-app 프로젝트 빌드 -> 도커파일 생성
working-directory: react-app
run: docker build -t ${{ env.REACT_ECR_REPOSITORY }} .
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Amazon ECR Private 로그인
uses: aws-actions/amazon-ecr-login@v2
- name: Tag and push React Docker image
run: |
docker tag ${{ env.REACT_ECR_REPOSITORY }}:latest ${{ env.ECR_REGISTRY }}/${{ env.REACT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker push ${{ env.ECR_REGISTRY }}/${{ env.REACT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: 최신 React 태스크 정의 가져오기
id: get-task-latest-react
run: |
aws ecs describe-task-definition --task-definition ${{ env.REACT_ECS_TASK_DEFINITION }} --query taskDefinition > ${{ env.REACT_ECS_TASK_DEFINITION }}.json
cat ${{ env.REACT_ECS_TASK_DEFINITION }}.json
echo "::set-output name=task-def-file::${{ env.REACT_ECS_TASK_DEFINITION }}.json"
- name: Amazon ECS 태스크 정의 배포 (React)
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.get-task-latest-react.outputs.task-def-file }}
service: ${{ env.REACT_ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
cd-chatbot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
if: contains(github.ref, 'main')
uses: actions/checkout@v2
- name: chatbot-app 경로의 env 파일 생성
working-directory: chatbot-app
run: |
echo "${{ env.CHATBOT_ENV }}" > .env
shell: bash
- name: chatbot-app 프로젝트 빌드 -> 도커파일 생성
working-directory: chatbot-app
run: docker build -t ${{ env.CHATBOT_ECR_REPOSITORY }} .
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Amazon ECR Private 로그인
uses: aws-actions/amazon-ecr-login@v2
- name: Tag and push Chatbot Docker image
run: |
docker tag ${{ env.CHATBOT_ECR_REPOSITORY }}:latest ${{ env.ECR_REGISTRY }}/${{ env.CHATBOT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker push ${{ env.ECR_REGISTRY }}/${{ env.CHATBOT_ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: 최신 Chatbot 태스크 정의 가져오기
id: get-task-latest-chatbot
run: |
aws ecs describe-task-definition --task-definition ${{ env.CHATBOT_ECS_TASK_DEFINITION }} --query taskDefinition > ${{ env.CHATBOT_ECS_TASK_DEFINITION }}.json
cat ${{ env.CHATBOT_ECS_TASK_DEFINITION }}.json
echo "::set-output name=task-def-file::${{ env.CHATBOT_ECS_TASK_DEFINITION }}.json"
- name: Amazon ECS 태스크 정의 배포 (chatbot)
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.get-task-latest-chatbot.outputs.task-def-file }}
service: ${{ env.CHATBOT_ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true