-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
294 lines (260 loc) · 11.3 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
# stages to run
stages:
- build-client
- integration-test
- buildIT4I
- deployIT4I
- buildLRZ
- deployLRZ
- buildPROD
- deployPROD
# saving project libraries to GitLab runner cache for faster installation
#cache:
# paths:
# - $CI_PROJECT_DIR/lexis-be/node_modules/**/*
# - $CI_PROJECT_DIR/cache/Cypress
#- $CI_PROJECT_DIR/lexis-client/node_modules/**/*
# - $CI_PROJECT_DIR/integration-test/node_modules/**/*
# JOB: build portal client
build-client:
# run this job in build stage
stage: build-client
# install docker image based on debian with Node.js version 12
image: node:14-alpine
variables:
#NODE_ENV: production
NODE_ENV: development
cache:
- key:
files:
- $CI_PROJECT_DIR/lexis-client/package.json
paths:
- $CI_PROJECT_DIR/lexis-client/node_modules/
# save artifacts (files) with configuration and build folder with portal client
artifacts:
paths:
- $CI_PROJECT_DIR/lexis-client/build
- $CI_PROJECT_DIR/lexis-client/src/config/default.json
expire_in: 1 day
# script executed before main script
before_script:
- apk add yarn git
- git submodule init
- git submodule update --recursive
- cd lexis-client/
# create configuration file for portal client
- cp $CI_PROJECT_DIR/lexis-client/src/config/config.default.json $CI_PROJECT_DIR/lexis-client/src/config/default.json
# install required packages
- yarn --silent
# main script - build portal client application
script:
- yarn run lint
# - yarn run build # production
- yarn run build-dev # development - enable source map
# JOB: install and run Cypress integration tests
integration-test:
# run this job in intagration_test stage
stage: integration-test
dependencies:
- build-client
# install docker image based on debian with Node.js version 12
image: node:14
cache:
- key:
files:
- $CI_PROJECT_DIR/integration-test/package.json
paths:
- $CI_PROJECT_DIR/integration-test/node_modules/
- key:
files:
- $CI_PROJECT_DIR/lexis-be/package.json
paths:
- $CI_PROJECT_DIR/lexis-be/node_modules/
- key:
files:
- $CI_PROJECT_DIR/integration-test/cypress/integration/
paths:
- $CI_PROJECT_DIR/cache/Cypress
# save artifacts (files) with logs, screenshots and videos of failed tests
artifacts:
when: on_failure
paths:
- $CI_PROJECT_DIR/integration-test/cypress/videos
- $CI_PROJECT_DIR/integration-test/cypress/screenshots
- $CI_PROJECT_DIR/integration-test/logs
expire_in: 1 day
# pass environmental variables to container
variables:
NODE_ENV: staging
# set cache folder for cypress to prevent permission errors
CYPRESS_CACHE_FOLDER: $CI_PROJECT_DIR/cache/Cypress
# script executed before main script
before_script:
- apt-get update
# install graphical packages required by cypress
- apt-get install -y libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 xvfb
# move build folder with client portal to integrations-test folder
- mv $CI_PROJECT_DIR/lexis-client/build/ $CI_PROJECT_DIR/integration-test/
- cd lexis-be/
# install fake backend dependencies
- yarn --silent
- cd ../integration-test/
# install dependencies for testing
- yarn --silent
- yarn add [email protected]
- yarn add cypress-file-upload
- npm install -g pm2
# main script - run tests
script:
# before launching pm2's daemonized processes, it's needed to launch following command to clear all residual processes from previous runs, which would instead disallow proper fresh start of desired processes
- pm2 update
# launch portal hosting and fake backend in containers by pm2 (Advanced process manager)
# Fake backend returns MANAGER as user role
- pm2 start run-app-staging-manager.config.js
# verify cypress installation
- $(npm bin)/cypress verify
# run test in integration test for user role MANAGER
- $(npm bin)/cypress run --spec cypress/integration/flows/user-roles-manager.test.js
# stop pm2 containers
- pm2 stop run-app-staging-manager.config.js
# Fake backend returns ENGINEER as user role
- pm2 start run-app-staging-engineer.config.js
# run test in integration test for user role ENGINEER
- $(npm bin)/cypress run --spec cypress/integration/flows/user-roles-engineer.test.js
# stop pm2 containers
- pm2 stop run-app-staging-engineer.config.js
# Fake backend returns DAT_MGR as user role
- pm2 start run-app-staging-datmanager.config.js
# run test in integration test for user role DAT_MGR
- $(npm bin)/cypress run --spec cypress/integration/flows/user-roles-datmanager.test.js
buildIT4I:
stage: buildIT4I
image: docker:latest
dependencies:
- integration-test
before_script:
- docker info
- cp build/Dockerfile .
- echo "[url \"https://gitlab-ci-token:${CI_JOB_TOKEN}@code.it4i.cz/\"]" > gitconfig
- echo "insteadOf = https://code.it4i.cz/" >> gitconfig
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASS" $DOCKER_REGISTRY_URL
- sed -i "s/HPC/IT4I/g" Dockerfile
script:
- docker pull $CI_REGISTRY_IMAGE:IT4I-latest || true
- docker build --network host --build-arg COMPILATION="$(date +%s)" --cache-from registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-latest -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-$(cat VERSION) -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-$(cat VERSION)-$CI_COMMIT_SHORT_SHA -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-latest .
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-latest
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-$(cat VERSION)
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-$(cat VERSION)-$CI_COMMIT_SHORT_SHA
only:
refs:
- development
deployIT4I:
stage: deployIT4I
image: hyperized/openssh-client:latest
dependencies:
- buildIT4I
before_script:
- eval $(ssh-agent -s)
- cat ${CI_DEPLOY_KEY} | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan portal.msad.it4i.lexis.tech >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh [email protected] "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASS $DOCKER_REGISTRY_URL"
- ssh [email protected] "docker-compose stop lexis-portal-be"
- ssh [email protected] "docker rmi -f registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-latest"
- ssh [email protected] "docker pull registry.msad.it4i.lexis.tech:5000/lexis-portal-be:IT4I-latest"
- ssh [email protected] "yes | docker-compose up -d lexis-portal-be"
- ssh [email protected] "docker logout $DOCKER_REGISTRY_URL"
only:
refs:
- development
buildLRZ:
stage: buildLRZ
image: docker:latest
dependencies:
- integration-test
before_script:
- docker info
- cp build/Dockerfile .
- echo "[url \"https://gitlab-ci-token:${CI_JOB_TOKEN}@code.it4i.cz/\"]" > gitconfig
- echo "insteadOf = https://code.it4i.cz/" >> gitconfig
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASS" $DOCKER_REGISTRY_URL
- sed -i "s/HPC/LRZ/g" Dockerfile
script:
- docker pull $CI_REGISTRY_IMAGE:LRZ-latest || true
- docker build --network host --build-arg COMPILATION="$(date +%s)" --cache-from registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-latest -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-$(cat VERSION) -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-$(cat VERSION)-$CI_COMMIT_SHORT_SHA -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-latest .
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-latest
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-$(cat VERSION)
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-$(cat VERSION)-$CI_COMMIT_SHORT_SHA
only:
refs:
- development
deployLRZ:
stage: deployLRZ
image: hyperized/openssh-client:latest
dependencies:
- buildLRZ
before_script:
- eval $(ssh-agent -s)
- cat ${CI_DEPLOY_KEY_LRZ} | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan ${CI_HOST_LRZ} >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASS $DOCKER_REGISTRY_URL"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "docker-compose stop lexis-portal-be"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "yes | docker-compose rm lexis-portal-be"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "docker rmi -f registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-latest"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "docker pull registry.msad.it4i.lexis.tech:5000/lexis-portal-be:LRZ-latest"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "yes | docker-compose up -d lexis-portal-be"
- ssh ${CI_DEPLOY_USER_LRZ}@${CI_HOST_LRZ} "docker logout $DOCKER_REGISTRY_URL"
only:
refs:
- development
buildPROD:
stage: buildPROD
image: docker:latest
dependencies:
- integration-test
before_script:
- docker info
- cp build/DockerfilePROD ./Dockerfile
- echo "[url \"https://gitlab-ci-token:${CI_JOB_TOKEN}@code.it4i.cz/\"]" > gitconfig
- echo "insteadOf = https://code.it4i.cz/" >> gitconfig
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASS" $DOCKER_REGISTRY_URL
- sed -i "s/HPC/PROD/g" Dockerfile
script:
- docker pull $CI_REGISTRY_IMAGE:PROD-latest || true
- docker build --network host --build-arg COMPILATION="$(date +%s)" --cache-from registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-latest -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-$(cat VERSION) -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-$(cat VERSION)-$CI_COMMIT_SHORT_SHA -t registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-latest .
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-latest
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-$(cat VERSION)
- docker push registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-$(cat VERSION)-$CI_COMMIT_SHORT_SHA
only:
refs:
- master
deployPROD:
stage: deployPROD
image: hyperized/openssh-client:latest
dependencies:
- buildPROD
before_script:
- eval $(ssh-agent -s)
- cat ${CI_DEPLOY_KEY} | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan ${CI_HOST_PROD_IT4I} >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh deploy@${CI_HOST_PROD_IT4I} "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASS $DOCKER_REGISTRY_URL"
- ssh deploy@${CI_HOST_PROD_IT4I} "docker-compose stop lexis-portal-be"
- ssh deploy@${CI_HOST_PROD_IT4I} "yes | docker-compose rm lexis-portal-be"
- ssh deploy@${CI_HOST_PROD_IT4I} "docker rmi -f registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-latest"
- ssh deploy@${CI_HOST_PROD_IT4I} "docker pull registry.msad.it4i.lexis.tech:5000/lexis-portal-be:PROD-latest"
- ssh deploy@${CI_HOST_PROD_IT4I} "yes | docker-compose up -d lexis-portal-be"
- ssh deploy@${CI_HOST_PROD_IT4I} "docker logout $DOCKER_REGISTRY_URL"
only:
refs:
- master