-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
396 lines (356 loc) · 10.7 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# Notes:
# Branch front/* will run check-frontend, test-frontend-0, test-frontend-1, test-frontend-2
# Branch back/* will run build-backend
# Branch product/* will run build-backend, build-frontend, package-product
# Branch full/* will run build-backend, check-frontend, test-frontend-0, test-frontend-1, test-frontend-2, build-frontend, package-product
# Branch master will run build-backend, check-frontend, test-frontend-0, test-frontend-1, test-frontend-2, build-frontend, build-frontend-pages,
# package-product-master, pages, sonar-frontend, sonar-backend
# Other branches will run build-backend, check-frontend, test-frontend-0, test-frontend-1, test-frontend-2, build-frontend, package-product
# Tags will run build-backend, build-frontend, release-product
# Runs tests and debug procedure detailed EOF
stages:
- build
- report
- package
- integration
variables:
# it is also referenced in ci/settings.xml
M2_STAGING_DIRECTORY: staging
M2_CACHED_REPOSITORY: m2cache
YARN_CACHE_DIRECTORY: yarncache
.mvn-java-8: &mvn-java-8
image: maven:3-jdk-8-alpine
before_script:
- source ci/mvn-helpers.sh
after_script:
- source ci/mvn-helpers.sh
- maven ch.ringler.tools:m2cachecleanup:1.0.4:cleanup-cache
cache:
key: mvn-java-8
paths:
- $M2_CACHED_REPOSITORY
tags:
- docker
.node-10: &node-java-yarn
image: registry.gitlab.com/linagora/node-java-yarn-docker:n10-j8
before_script:
# see https://github.com/yarnpkg/yarn/issues/986 or https://github.com/yarnpkg/yarn/issues/988 for optimizing
- yarn config set cache-folder $PWD/$YARN_CACHE_DIRECTORY --global
- yarn global add spa-http-server
- du --human-readable --summarize $PWD/$YARN_CACHE_DIRECTORY || true
- cd frontend
- export PATH=`yarn bin`:$PATH
- time yarn --frozen-lockfile --link-duplicates --non-interactive
- yarn run webdriver-manager update --versions.chrome=73.0.3683.68
- ./node_modules/protractor/bin/webdriver-manager update --versions.chrome=73.0.3683.68
- du --human-readable --summarize node_modules || true
- cd ..
cache:
key: node-yarn
paths:
- $YARN_CACHE_DIRECTORY
tags:
- docker
pages:
image: alpine:3.6
variables:
GIT_STRATEGY: none
stage: package
allow_failure: true
only:
# pages are only built and deployed from master
- master
dependencies:
- build-backend
- build-frontend-pages
script:
- mv frontend-demo public
- mv backend-apidocs public/apidocs
artifacts:
expire_in: 1 day
paths:
- public
tags:
- docker
build-backend:
<<: *mvn-java-8
stage: build
except:
# we don't want to build nor test the backend in front/*
- /^front\/.*$/
script:
# let's lock the version used for SNAPSHOT dependencies to
# ensure they are the same in the other jobs
- maven --projects backend --also-make versions:lock-snapshots
# deploy to the staging directory
# ignore liquibase info logs flooding (to prevent gitlab log size hitting its default limit)
# See issue https://gitlab.com/linagora/petals-cockpit/issues/544
- maven_build --projects backend --also-make deploy | grep -vE "^INFO \[.*\] liquibase.*$"
# build the docs
- maven --projects backend --also-make com.webcohesion.enunciate:enunciate-slim-maven-plugin:docs && mv backend/target/site/apidocs backend-apidocs || true # this can fail
artifacts:
expire_in: 1 week
paths:
- backend-apidocs
- $M2_STAGING_DIRECTORY
- "**/target"
tags:
- docker
sonar-backend:
<<: *mvn-java-8
variables:
GIT_DEPTH: "0"
stage: report
allow_failure: true
dependencies:
- build-backend
only:
- master
script:
- maven_build --file backend/pom.xml sonar:sonar -Dsonar.projectKey=petals-cockpit-backend
check-frontend:
<<: *node-java-yarn
stage: build
except:
# we don't want to check the frontend in back/* and product/*
- /^back\/.*$/
- /^product\/.*$/
# no tests on tags
- tags
script:
- cd frontend
# copyright and lint
- time yarn run check
tags:
- docker
test-frontend-0:
<<: *node-java-yarn
stage: build
except:
# we don't want to test the frontend in back/* and product/*
- /^back\/.*$/
- /^product\/.*$/
# no tests on tags
- tags
script:
- cd frontend
# unit tests
- time yarn run test:ci
# e2e
# tests protractor
- time yarn run e2e:ci --port 4200 --webdriver-update false
# build the frontend no ldap mode
- time yarn run build:no-ldap:ci
# serve the frontend
- nohup http-server --push-state --silent -p 4200 dist &
# save the PID as we run it in background
- echo $! > pid-nohup.txt
- sleep 5s
- time yarn cypress:e2e-no-ldap
- kill -9 $(cat pid-nohup.txt)
- rm pid-nohup.txt
artifacts:
expire_in: 1 week
paths:
- frontend/coverage/lcov.info
tags:
- docker
test-frontend-1:
<<: *node-java-yarn
stage: build
except:
# we don't want to test the frontend in back/* and product/*
- /^back\/.*$/
- /^product\/.*$/
# no tests on tags
- tags
script:
- cd frontend
# build the frontend ldap mode
- time yarn run build:ldap:ci
# serve the frontend
- nohup http-server --push-state --silent -p 4200 dist &
# save the PID as we run it in background
- echo $! > pid-nohup.txt
- sleep 5s
- time yarn cypress:e2e-test-frontend-1
- kill -9 $(cat pid-nohup.txt)
- rm pid-nohup.txt
tags:
- docker
test-frontend-2:
<<: *node-java-yarn
stage: build
except:
# we don't want to test the frontend in back/* and product/*
- /^back\/.*$/
- /^product\/.*$/
# no tests on tags
- tags
script:
- cd frontend
# build the frontend ldap mode
- time yarn run build:ldap:ci
# serve the frontend
- nohup http-server --push-state --silent -p 4200 dist &
# save the PID as we run it in background
- echo $! > pid-nohup.txt
- sleep 5s
- time yarn cypress:e2e-test-frontend-2
- kill -9 $(cat pid-nohup.txt)
- rm pid-nohup.txt
tags:
- docker
sonar-frontend:
<<: *node-java-yarn
variables:
GIT_DEPTH: "0"
stage: report
allow_failure: true
dependencies:
- test-frontend-0
only:
- master
script:
- cd frontend
- yarn run sonar-scanner -Dsonar.host.url=$SONAR_HOST_URL
build-frontend:
<<: *node-java-yarn
stage: build
except:
# we don't want to build the frontend, only test it (with test-frontend-0, test-frontend-1 and test-frontend-2) in front/*
- /^front\/.*$/
# we don't want to build the frontend in back/*
- /^back\/.*$/
script:
- cd frontend
# build the final frontend for the product
- time yarn run build:product:ci && mv dist ../frontend-dist
- du --human-readable --summarize ../frontend-dist
artifacts:
expire_in: 1 week
paths:
- frontend-dist
tags:
- docker
build-frontend-pages:
<<: *node-java-yarn
stage: build
only:
# pages are only built and deployed from master
- master
script:
- cd frontend
# build the demo for the gitlab pages
- time yarn run build:demo:ci && mv dist ../frontend-demo || true # this can fail
- du --human-readable --summarize ../frontend-demo || true
artifacts:
expire_in: 1 day
paths:
- frontend-demo
tags:
- docker
.build-product: &build-product
<<: *mvn-java-8
stage: package
dependencies:
- build-backend
- build-frontend
script:
- mv frontend-dist frontend/dist
- maven dependency:purge-local-repository --non-recursive -DmanualInclude="org.ow2.petals:petals-cockpit-server,org.ow2.petals:petals-cockpit-parent" -DreResolve=false -DsnapshotsOnly=true
- maven --projects cockpit verify antrun:run@build-product-dist
- export COCKPIT_VERSION=`ls cockpit/target/petals-cockpit-*-capsule.jar | sed --regexp-extended 's/.*petals-cockpit-(.*)-capsule.jar/\1/'`
# see https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/1664
- echo $COCKPIT_VERSION > version.txt
- mv cockpit/target/dist petals-cockpit-$COCKPIT_VERSION
tags:
- docker
# build the product for release tags, the artifact has no expiration
release-product:
<<: *build-product
only:
- tags
artifacts:
name: petals-cockpit-$(cat version.txt)
paths:
- petals-cockpit-*
tags:
- docker
package-product-master:
<<: *build-product
only:
- master
artifacts:
name: petals-cockpit-$(cat version.txt)-${CI_BUILD_REF:0:7}
paths:
- petals-cockpit-*
tags:
- docker
package-product:
<<: *build-product
except:
# covered by package-product-master
- master
# covered by release-product
- tags
# we don't want to build the final product in front/* and back/*
- /^front\/.*$/
- /^back\/.*$/
artifacts:
expire_in: 1 week
name: petals-cockpit-$(cat version.txt)-${CI_BUILD_REF:0:7}
paths:
- petals-cockpit-*
tags:
- docker
### For now, we don't use e2e-product. It will be refactored later ..
# e2e-product:
# <<: *node-java-yarn
# stage: integration
# except:
# # we don't want to test the final product in front/*, back/* and product/*
# - /^front\/.*$/
# - /^back\/.*$/
# - /^product\/.*$/
# - tags
# dependencies:
# # one or the other
# - package-product
# - package-product-master
# # not able to connect to JMI using docker, for now e2e test are without petals
# # services:
# # - petals/petals-esb-test
# variables:
# COCKPIT_CONFIG: e2e/e2e-backend-config.yml
# script:
# # TODO reuse script?
# - export JAR=$(ls -1 petals-cockpit-*/lib/petals-cockpit-*.jar 2>/dev/null)
# - export COCKPIT="java -ea -jar $JAR"
# - time $COCKPIT db migrate $COCKPIT_CONFIG --migrations e2e/migrations.xml
# - nohup $COCKPIT server $COCKPIT_CONFIG > e2e/logs/cockpit-e2e-run.out.log 2> e2e/logs/cockpit-e2e-run.err.log &
# - cd frontend
# - sleep 2
# - time yarn run e2e:product --webdriver-update false
# # Protractor tests are unstable and may fail unexpectedly
# # this workaround has to be removed if we stop relying on protractor
# artifacts:
# expire_in: 1 week
# name: ${CI_JOB_NAME}-backendLogs-${CI_BUILD_REF:0:7}
# paths:
# - e2e/logs/
# retry: 1
# tags:
# - docker
### Test gitlab ci
# Install with apt: gitlab-ci-multi-runner (& maybe docker.io)
# git commit changes locally
# in cockpit root directory:
# > gitlab-ci-multi-runner exec docker {job-name}
# To test with local docker images
# in Dockerfile image directory, builds local image:
# > docker build . -t {custom-image-name}:{image-tag}
# in cockpit root directory:
# change local gitlab-ci script with temporary image
# run using local image
# > gitlab-ci-multi-runner exec docker --docker-pull-policy=never {job-name}