-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
353 lines (322 loc) · 11.8 KB
/
.gitlab-ci.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# This file is a template, and might need editing before it works on your project.
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
#
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
stages: # List of stages for jobs, and their order of execution
- build
- docker-build
# - sonar
# - test
- deploy
test:
stage: build
script:
- echo "merge request"
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
backend-build-job: # This job runs in the build stage, which runs first.
stage: build
image: openjdk:21-jdk-slim
script:
- echo "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- echo "backend build start"
- ls -la
- cd backend
- ls -la
- chmod +x ./gradlew
- ./gradlew wrapper
- ./gradlew clean build
- docker image prune -af
- echo "backend build end"
artifacts:
paths:
- backend/build/libs/*.jar # JAR 파일을 빌드 아티팩트로 저장
expire_in: 1 week
before_script:
- echo "Starting CI/CD pipeline"
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- backend/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
backend-docker-build-job:
image: docker:latest
stage: docker-build
script:
- echo "backend docker build start"
- cd backend
- echo "whoami"
- whoami
- echo "ls -la"
- ls -la
- echo "pwd"
- pwd
- export TAG=$(date +%Y%m%d%H%M%S)
- docker build -t imjunhyuk/urecar:$TAG .
- docker tag imjunhyuk/urecar:$TAG imjunhyuk/urecar:latest
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD # Docker Hub에 로그인
- docker push imjunhyuk/urecar:latest # Docker Hub로 이미지 푸시
- docker push imjunhyuk/urecar:$TAG
- echo "backend docker build end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- backend/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
backend-deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
script:
- echo "backend deploy start"
- ssh -o StrictHostKeyChecking=no [email protected] "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD &&
docker pull imjunhyuk/urecar:latest &&
docker-compose -f /home/ubuntu/docker/backend/docker-compose.yml up -d " # image pull from hub and docker-compose로 컨테이너 실행
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose down"
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose up -d"
- echo "backend deploy end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- backend/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
ai-docker-build-job:
stage: docker-build
script:
- echo "ai docker build start"
- cd ai/server
- export TAG=$(date +%Y%m%d%H%M%S)
- docker build -t imjunhyuk/urecar_ai:$TAG .
- docker tag imjunhyuk/urecar_ai:$TAG imjunhyuk/urecar_ai:latest
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD # Docker Hub에 로그인
- docker push imjunhyuk/urecar_ai:latest # Docker Hub로 이미지 푸시
- docker push imjunhyuk/urecar_ai:$TAG
- echo "ai docker build end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- ai/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
ai-deploy-job:
stage: deploy
script:
- echo "ai deploy start"
- ssh -o StrictHostKeyChecking=no [email protected] "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD &&
docker pull imjunhyuk/urecar_ai:latest &&
docker-compose -f /home/ubuntu/docker/ai/docker-compose.yml up -d " # image pull from hub and docker-compose로 컨테이너 실행
- echo "ai deploy end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- ai/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
outbox-build-job: # This job runs in the build stage, which runs first.
stage: build
image: openjdk:21-jdk-slim
script:
- echo "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- echo "outbox build start"
- ls -la
- cd outbox-kafka-producer
- ls -la
- chmod +x ./gradlew
- ./gradlew wrapper
- ./gradlew clean build
- echo "outbox build end"
artifacts:
paths:
- outbox-kafka-producer/build/libs/*.jar # JAR 파일을 빌드 아티팩트로 저장
expire_in: 1 week
before_script:
- echo "Starting CI/CD pipeline"
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- outbox-kafka-producer/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
outbox-docker-build-job:
image: docker:latest
stage: docker-build
script:
- echo "outbox docker build start"
- cd outbox-kafka-producer
- echo "whoami"
- whoami
- echo "ls -la"
- ls -la
- echo "pwd"
- pwd
- export TAG=$(date +%Y%m%d%H%M%S)
- docker build -t imjunhyuk/urecar_outbox:$TAG .
- docker tag imjunhyuk/urecar_outbox:$TAG imjunhyuk/urecar_outbox:latest
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD # Docker Hub에 로그인
- docker push imjunhyuk/urecar_outbox:latest # Docker Hub로 이미지 푸시
- docker push imjunhyuk/urecar_outbox:$TAG
- echo "outbox docker build end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- outbox-kafka-producer/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
outbox-deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
script:
- echo "outbox deploy start"
- ssh -o StrictHostKeyChecking=no [email protected] "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD &&
docker pull imjunhyuk/urecar_outbox:latest &&
docker-compose -f /home/ubuntu/docker/outbox/docker-compose.yml up -d " # image pull from hub and docker-compose로 컨테이너 실행
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose down"
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose up -d"
- echo "outbox deploy end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- outbox-kafka-producer/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
# --------------------------------
notification-build-job: # This job runs in the build stage, which runs first.
stage: build
image: openjdk:21-jdk-slim
script:
- echo "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- echo "notification build start"
- ls -la
- cd notification
- ls -la
- chmod +x ./gradlew
- ./gradlew wrapper
- ./gradlew clean build
- echo "notification build end"
artifacts:
paths:
- notification/build/libs/*.jar # JAR 파일을 빌드 아티팩트로 저장
expire_in: 1 week
before_script:
- echo "Starting CI/CD pipeline"
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- notification/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
notification-docker-build-job:
image: docker:latest
stage: docker-build
script:
- echo "notification docker build start"
- cd notification
- echo "whoami"
- whoami
- echo "ls -la"
- ls -la
- echo "pwd"
- pwd
- export TAG=$(date +%Y%m%d%H%M%S)
- docker build -t imjunhyuk/urecar_notification:$TAG .
- docker tag imjunhyuk/urecar_notification:$TAG imjunhyuk/urecar_notification:latest
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD # Docker Hub에 로그인
- docker push imjunhyuk/urecar_notification:latest # Docker Hub로 이미지 푸시
- docker push imjunhyuk/urecar_notification:$TAG
- echo "notification docker build end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- notification/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
notification-deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
script:
- echo "notification deploy start"
- ssh -o StrictHostKeyChecking=no [email protected] "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD &&
docker pull imjunhyuk/urecar_notification:latest &&
docker-compose -f /home/ubuntu/docker/notification/docker-compose.yml up -d " # image pull from hub and docker-compose로 컨테이너 실행
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose down"
# - ssh -o StrictHostKeyChecking=no [email protected] "cd /home/ubuntu/docker/backend && docker-compose up -d"
- echo "notification deploy end"
after_script:
- docker logout
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
changes:
- notification/**/*
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
#sonarqube-check:
# image: gradle:jdk21
# stage: sonar
# variables:
# SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
# GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
# cache:
# key: "${CI_JOB_NAME}"
# paths:
# - .sonar/cache
# script:
# - cd backend
# - gradle sonar
# allow_failure: true
# only:
# - develop
# build-job: # This job runs in the build stage, which runs first.
# stage: build
# script:
# - echo "Compiling the code..."
# - echo "Compile complete."
# unit-test-job: # This job runs in the test stage.
# stage: test # It only starts when the job in the build stage completes successfully.
# script:
# - echo "Running unit tests... This will take about 60 seconds."
# - sleep 60
# - echo "Code coverage is 90%"
# lint-test-job: # This job also runs in the test stage.
# stage: test # It can run at the same time as unit-test-job (in parallel).
# script:
# - echo "Linting code... This will take about 10 seconds."
# - sleep 10
# - echo "No lint issues found."
# deploy-job: # This job runs in the deploy stage.
# stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
# environment: production
# script:
# - echo "Deploying application..."
# - echo "Application successfully deployed."