-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
339 lines (318 loc) · 7.68 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
default:
tags:
- docker
stages:
- prepare
- test
- build
- staging
- deploy
variables:
RULES_CHANGES_PATH: "**/*"
CLIENT_CONTAINER_IMAGE: myhsd:${CI_COMMIT_SHORT_SHA}
CLIENT_FULL_IMAGE_NAME: $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/$CLIENT_CONTAINER_IMAGE
SERVER_CONTAINER_IMAGE: myhsd-server:${CI_COMMIT_SHORT_SHA}
SERVER_FULL_IMAGE_NAME: $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/$SERVER_CONTAINER_IMAGE
.base-rules:
rules:
- if: $CI_MERGE_REQUEST_IID
changes:
- $RULES_CHANGES_PATH
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $DEPLOY_BRANCH
when: always
- if: $CI_COMMIT_BRANCH == "develop"
when: always
- if: $CI_COMMIT_REF_NAME =~ /pipeline/ # Run pipeline if branch contains String "pipeline" to enable testing
when: manual
allow_failure: true
.server:
variables:
RULES_CHANGES_PATH: "server/**/*"
.client:
variables:
RULES_CHANGES_PATH: "client/**/*"
.staging-rules:
rules:
- if: $CI_COMMIT_BRANCH == "develop"
when: manual
- if: $CI_COMMIT_REF_NAME =~ /pipeline/ # Run pipeline if branch contains String "pipeline" to enable testing
when: manual
.deploy-rules:
rules:
- if: $CI_COMMIT_BRANCH == $DEPLOY_BRANCH
- if: $CI_COMMIT_REF_NAME =~ /pipeline/ # Run pipeline if branch contains String "pipeline" to enable testing
when: manual
######################################### Prepare
client_node:
stage: prepare
extends:
- .base-rules
- .client
image: node:lts-alpine
needs: []
script:
- cd client
- npm ci
cache:
untracked: true
key: client-$CI_COMMIT_REF_SLUG
paths:
- client/node_modules
server_node:
stage: prepare
extends:
- .base-rules
- .server
image: node:lts-alpine
needs: []
before_script:
- apk add g++ make py3-pip
script:
- cd server
- npm ci
cache:
untracked: true
key: server-$CI_COMMIT_REF_SLUG
paths:
- server/node_modules
######################################### Test
client_lint:
stage: test
extends:
- .base-rules
- .client
image: node:lts-alpine
needs: ["client_node"]
script:
- cd client
- npm run lint
- npm run style:check
cache:
untracked: true
key: client-$CI_COMMIT_REF_SLUG
paths:
- client/node_modules
server_lint:
stage: test
extends:
- .base-rules
- .server
image: node:lts-alpine
needs: ["server_node"]
before_script:
- apk add g++ make py3-pip
script:
- cd server
- npm run lint
- npm run style:check
cache:
untracked: true
key: server-$CI_COMMIT_REF_SLUG
paths:
- server/node_modules
client_test:
stage: test
extends:
- .base-rules
- .client
image: node:lts-alpine
needs: ["client_node"]
script:
- cd client
- npm run test:ci
coverage: '/Lines {8}: \d+\.\d+%/'
cache:
untracked: true
key: client-$CI_COMMIT_REF_SLUG
paths:
- client/node_modules
artifacts:
when: always
paths:
- client/junit.xml
reports:
junit: client/junit.xml
coverage_report:
coverage_format: cobertura
path: client/coverage/cobertura-coverage.xml
server_test:
stage: test
extends:
- .base-rules
- .server
image: node:lts-alpine
needs: ["server_node"]
before_script:
- apk add g++ make py3-pip
script:
- cd server
- npm run test:ci
coverage: '/Lines {8}: \d+\.\d+%/'
cache:
untracked: true
key: server-$CI_COMMIT_REF_SLUG
paths:
- server/node_modules
artifacts:
when: always
paths:
- server/junit.xml
reports:
junit: server/junit.xml
coverage_report:
coverage_format: cobertura
path: server/coverage/cobertura-coverage.xml
######################################### Build
client_build:
stage: build
extends:
- .base-rules
- .client
image: node:lts-alpine
needs: ["client_node"]
script:
- cd client
- CI=$WARNINGS_AS_ERRORS GENERATE_SOURCEMAP=false npm run build
artifacts:
expire_in: 1 week
paths:
- client/build
cache:
untracked: true
key: client-$CI_COMMIT_REF_SLUG
paths:
- client/node_modules
server_build:
stage: build
extends:
- .base-rules
- .server
image: node:lts-alpine
needs: ["server_node"]
before_script:
- apk add g++ make py3-pip
script:
- cd server
- CI=$WARNINGS_AS_ERRORS npm run build
artifacts:
expire_in: 1 week
paths:
- server/dist
cache:
untracked: true
key: server-$CI_COMMIT_REF_SLUG
paths:
- server/node_modules
client_build_docker:
stage: build
extends:
- .deploy-rules
- .staging-rules
- .client
image: docker:latest
services:
- docker:dind
needs: ["client_build"]
dependencies:
- client_build
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- echo "$DOCKER_PASSWORD" | docker login https://${DOCKER_REGISTRY} -u $DOCKER_USER --password-stdin
- cd client
- docker build -t $CLIENT_CONTAINER_IMAGE .
- echo "$CLIENT_FULL_IMAGE_NAME"
- docker tag $CLIENT_CONTAINER_IMAGE $CLIENT_FULL_IMAGE_NAME
- docker tag $CLIENT_FULL_IMAGE_NAME $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/myhsd:latest
- docker push $CLIENT_FULL_IMAGE_NAME
- docker push $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/myhsd:latest
server_build_docker:
stage: build
extends:
- .deploy-rules
- .staging-rules
- .server
image: docker:latest
services:
- docker:dind
needs: ["server_build"]
dependencies:
- server_build
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- echo "$DOCKER_PASSWORD" | docker login https://${DOCKER_REGISTRY} -u $DOCKER_USER --password-stdin
- cd server
- docker build -t $SERVER_CONTAINER_IMAGE .
- echo "$SERVER_FULL_IMAGE_NAME"
- docker tag $SERVER_CONTAINER_IMAGE $SERVER_FULL_IMAGE_NAME
- docker tag $SERVER_FULL_IMAGE_NAME $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/myhsd-server:latest
- docker push $SERVER_FULL_IMAGE_NAME
- docker push $DOCKER_REGISTRY/$REGISTRY_NAMESPACE/myhsd-server:latest
######################################### Staging
client_staging:
stage: staging
extends:
- .staging-rules
- .client
image:
name: bitnami/kubectl:latest
entrypoint: [""]
needs: ["client_build_docker"]
environment:
name: Staging
url: $CLIENT_STAGING_URL
script:
- kubectl config get-contexts
- kubectl config use-context "$KUBE_CONTEXT"
- kubectl set image deployment/staging-myhsd staging-react=$CLIENT_FULL_IMAGE_NAME
server_staging:
stage: staging
extends:
- .staging-rules
- .server
image:
name: bitnami/kubectl:latest
entrypoint: [""]
needs: ["server_build_docker"]
environment:
name: Staging
url: $API_STAGING_URL
script:
- kubectl config get-contexts
- kubectl config use-context "$KUBE_CONTEXT"
- kubectl set image deployment/staging-myhsd-server staging-nest=$SERVER_FULL_IMAGE_NAME
######################################### Deploy
client_deploy:
stage: deploy
extends:
- .deploy-rules
- .client
image:
name: bitnami/kubectl:latest
entrypoint: [""]
needs: ["client_build_docker"]
environment:
name: Production
url: $CLIENT_URL
script:
- kubectl config get-contexts
- kubectl config use-context "$KUBE_CONTEXT"
- kubectl set image deployment/myhsd react=$CLIENT_FULL_IMAGE_NAME
server_deploy:
stage: deploy
extends:
- .deploy-rules
- .server
image:
name: bitnami/kubectl:latest
entrypoint: [""]
needs: ["server_build_docker"]
environment:
name: Production
url: $API_URL
script:
- kubectl config get-contexts
- kubectl config use-context "$KUBE_CONTEXT"
- kubectl set image deployment/myhsd-server nest=$SERVER_FULL_IMAGE_NAME