-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.gitlab-ci.yml
500 lines (444 loc) · 14.1 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# This CI/CD configuration provides a standard pipeline for
# * building services (docker-compose),
# * running code quality analysis,
# * creating a review app for tag "review-*",
# * and continuous deployment to production.
default:
tags:
- udocker02
variables:
#CI_DEBUG_TRACE: "true"
# Checking an already installed service may be disabled by setting environment variable
# 'CHECK_NEW_INSTANCE: "false"' (enabled by default).
#
# If you want to use only a standalone server to update the configuration, then set
# 'FLAG_USE_ONLY_IBCMD: "true"' (disabled by default).
CHECK_NEW_INSTANCE: "true"
FLAG_USE_ONLY_IBCMD: "false"
# Compose configuration files (docker-compose -f) and
# project name (docker-compose -p) for containers, volumes, and network prefix
DEPLOY_CONFIG: "production.yml"
DEPLOY_NAME: "$CI_PROJECT_NAME-production"
DEPLOY_NETWORK: "$CI_PROJECT_NAME-production"
# production and review app endpoints
DEPLOY_SERVER: "http://127.0.0.1"
DEPLOY_PORT: "8090"
REVIEW_PORT: "8091"
EDT_PROJECT_DIR: "Transmitter" # EDT src
# docker-compose services (1C and DB)
IB_SERVER: "srv"
IB_NAME: "transmitter"
DB_SERVER: "db"
DB_NAME: "transmitter"
BACKUP_PATH: "/var/backups" # backup before update
# init ib (users, roles)
INIT_DB_PATH: "https://github.com/astrizhachuk/Init-db-1c/releases/download"
INIT_DB_VERSION: "2.0.0"
# allure
ALLURE_LAUNCH_NAME: "$CI_PROJECT_NAME - $CI_COMMIT_SHORT_SHA"
ALLURE_LAUNCH_TAGS: "$CI_COMMIT_REF_NAME, $CI_COMMIT_TAG"
ALLURE_RESULTS: "reports/allure"
ALLURE_TESTPLAN_PATH: ./testplan.json
# va
# VA: "va.epf"
# VA_VERSION: "1.2.038.1"
PLATFORM_1C: "C:\\Program Files (x86)\\1cv8\\8.3.10.2667\\bin\\1cv8.exe"
CLIENT_1C: "C:\\Program Files (x86)\\1cv8\\8.3.10.2667\\bin\\1cv8c.exe"
INIT_DB_LOCAL: "C:\\deploying-db-1c\\epf\\InitDB.epf"
VA: "C:\\deploying-db-1c\\epf\\vanessa-automation-single.epf"
workflow:
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
- if: $CI_MERGE_REQUEST_IID
stages:
- build
- test
- srv
- db
- dump
- import
- apply
- update
- init
- ws
include:
- remote: 'https://raw.githubusercontent.com/astrizhachuk/onec-gitlab-ci/master/.ibcmd-ci.yml'
- remote: 'https://raw.githubusercontent.com/astrizhachuk/onec-gitlab-ci/master/.sonarqube-ci.yml'
.start_services: &start_services
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME up --no-start
- docker cp $DEPLOY_NETHASP ${DEPLOY_NAME}_${IB_SERVER}_1:/opt/1cv8/current/conf/nethasp.ini
- docker cp $DEPLOY_ONEC_CONFIG ${DEPLOY_NAME}_${IB_SERVER}_1:/opt/1cv8/current/conf/conf.cfg
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME start
.get_deploy_env: &get_deploy_env
- TAG_REGEX="^review-"
- if [[ $CI_COMMIT_TAG =~ $TAG_REGEX ]];
then
DEPLOY_NETWORK=$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG;
DEPLOY_NAME=$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG;
DEPLOY_PORT=$REVIEW_PORT;
fi
.rac_register_ib: &rac_register_ib
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME
exec -T
$IB_SERVER bash -c "/opt/1cv8/current/ras cluster --daemon &&
sleep 10s &&
/opt/1cv8/current/rac cluster list $IB_SERVER &&
/opt/1cv8/current/rac infobase
--cluster=\$(/opt/1cv8/current/rac cluster list $IB_SERVER | grep cluster | awk '{print \$3}')
create
--name=$IB_NAME
--dbms=PostgreSQL
--db-server=$DB_SERVER
--db-name=$DB_NAME
--locale=ru
--db-user=postgres
--license-distribution=allow
$IB_SERVER"
.update_ib: &update_ib
- docker run
--rm
--network=$DEPLOY_NETWORK
-v $CI_PROJECT_DIR:/build
-v $DEPLOY_NETHASP:/opt/1cv8/current/conf/nethasp.ini
-v $DEPLOY_ONEC_CONFIG:/opt/1cv8/current/conf/conf.cfg
$CI_REGISTRY/devops/onec-docker/client-vnc:$ONEC_VERSION
bash -c "/opt/1cv8/current/1cv8 DESIGNER
/IBConnectionString \"Srvr=$IB_SERVER;Ref=$IB_NAME;\"
$PARAMS_ADMIN_USER
/LoadConfigFromFiles /build/xml -Format Hierarchical /UpdateDBCfg
/DisableStartupMessages /DisableStartupDialogs
/out /build/load.log"
.init_ib: &init_ib
- docker run
--rm
--network=$DEPLOY_NETWORK
-v $CI_PROJECT_DIR:/build
-v $DEPLOY_NETHASP:/opt/1cv8/current/conf/nethasp.ini
-v $DEPLOY_ONEC_CONFIG:/opt/1cv8/current/conf/conf.cfg
-e WS_USER=$WS_USER
-e WS_PASSWORD=$WS_PASSWORD
$CI_REGISTRY/devops/onec-docker/client-vnc:$ONEC_VERSION
bash -c "/opt/1cv8/current/1cv8 ENTERPRISE
/IBConnectionString \"Srvr=$IB_SERVER;Ref=$IB_NAME;\"
$PARAMS_ADMIN_USER
/Execute /build/tools/init-db.epf /C\"file=/build/tools/users.json\""
docker login:
stage: .pre
script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
export xml:
stage: build
script:
- docker run
--rm
-v $CI_PROJECT_DIR:/build
$CI_REGISTRY/devops/onec-docker/edt:$ONEC_VERSION
bash -c "ring edt workspace export
--project /build/$EDT_PROJECT_DIR
--workspace-location tmp/w
--configuration-files /build/xml"
- sudo chown -R $USER $CI_PROJECT_DIR/xml #говорят, в api 1.41+ докер есть лучшее решение, чем chown
- sudo chown -R $USER $CI_PROJECT_DIR/$EDT_PROJECT_DIR/.settings
artifacts:
name: "xml-$CI_COMMIT_SHORT_SHA"
paths:
- xml
expire_in: 7 hours
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
download tools:
stage: build
script:
- docker run
--rm
-u $USER
-v $CI_PROJECT_DIR:/build
curlimages/curl:latest
-Lv -o /build/tools/init-db.epf $INIT_DB_PATH/$INIT_DB_VERSION/InitDB.epf
cache:
key: "init-$CI_COMMIT_SHORT_SHA"
paths:
- tools/init-db.epf
policy: push
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
srv up:
stage: srv
environment:
name: production
url: $DEPLOY_SERVER:$DEPLOY_PORT/api/hs/gitlab/services
on_stop: stop_production
script:
- if [[ $CHECK_NEW_INSTANCE == "true" ]]; then
if [[ ! -n $(docker volume ls -f name=$DEPLOY_NAME --format "{{.Name}}") ]]; then
FLAG_NEW_INSTANCE="true";
PARAMS_ADMIN_USER="";
else
FLAG_NEW_INSTANCE="false";
PARAMS_ADMIN_USER="/NАдминистратор";
fi
else
FLAG_NEW_INSTANCE="false";
PARAMS_ADMIN_USER="/NАдминистратор";
fi
- echo "FLAG_NEW_INSTANCE=$FLAG_NEW_INSTANCE" >> deploy.env
- echo "PARAMS_ADMIN_USER=$PARAMS_ADMIN_USER" >> deploy.env
- *start_services
artifacts:
reports:
dotenv: deploy.env
dependencies: []
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./
review srv up:
stage: srv
variables:
DEPLOY_NETWORK: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_NAME: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_PORT: $REVIEW_PORT
environment:
name: review/$CI_COMMIT_REF_SLUG
url: $DEPLOY_SERVER:$DEPLOY_PORT/api/hs/gitlab/services
on_stop: stop_review
script:
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME down -v
- *start_services
rules:
- if: $CI_COMMIT_TAG =~ /^review-/
create db:
stage: db
script:
- *get_deploy_env
- !reference [.ibcmd_create_ib, script]
dependencies: []
allow_failure: true
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
when: delayed
start_in: 5 seconds
register ib:
stage: db
script:
- *get_deploy_env
- *rac_register_ib
needs: ["create db"]
allow_failure: true
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
dump:
stage: dump
script:
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME stop ws
- !reference [.ibcmd_dump_ib, script]
dependencies: []
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./
import config:
stage: import
script:
- *get_deploy_env
- !reference [.ibcmd_config_import, script]
rules:
- if: ($CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/) && $FLAG_USE_ONLY_IBCMD == "true"
apply config:
stage: apply
script:
- *get_deploy_env
- !reference [.ibcmd_config_apply, script]
rules:
- if: ($CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/) && $FLAG_USE_ONLY_IBCMD == "true"
update:
stage: update
environment:
name: production
script:
- touch $CI_PROJECT_DIR/load.log
- *update_ib
- sudo chown -R $USER $CI_PROJECT_DIR/load.log
artifacts:
name: "log-$CI_COMMIT_SHORT_SHA"
paths:
- load.log
expire_in: 7 day
when: on_failure
rules:
- if: '$FLAG_USE_ONLY_IBCMD == "true"'
when: never
- if: $CI_COMMIT_TAG =~ /^v\d+./
review update:
stage: update
variables:
DEPLOY_NETWORK: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_NAME: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_PORT: $REVIEW_PORT
environment:
name: review/$CI_COMMIT_REF_SLUG
script:
- touch $CI_PROJECT_DIR/load.log
- *update_ib
- sudo chown -R $USER $CI_PROJECT_DIR/load.log
artifacts:
name: "log-$CI_COMMIT_SHORT_SHA"
paths:
- load.log
expire_in: 7 day
when: on_failure
dependencies: ["export xml"]
rules:
- if: '$FLAG_USE_ONLY_IBCMD == "true"'
when: never
- if: $CI_COMMIT_TAG =~ /^review-/
init db:
stage: init
environment:
name: production
script:
- if [[ $FLAG_NEW_INSTANCE == "false" ]]; then
exit 0;
fi
- *init_ib
cache:
key: "init-$CI_COMMIT_SHORT_SHA"
paths:
- tools/init-db.epf
policy: pull
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./
review init db:
stage: init
variables:
DEPLOY_NETWORK: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_NAME: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_PORT: $REVIEW_PORT
environment:
name: review/$CI_COMMIT_REF_SLUG
script:
- *init_ib
cache:
key: "init-$CI_COMMIT_SHORT_SHA"
paths:
- tools/init-db.epf
policy: pull
dependencies: []
rules:
- if: $CI_COMMIT_TAG =~ /^review-/
ws:
stage: ws
script:
- *get_deploy_env
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME restart ws
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
stop_production:
stage: .post
variables:
GIT_STRATEGY: none
script:
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME stop
environment:
name: production
action: stop
needs: ["srv up"]
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./
when: manual
stop_review:
stage: .post
variables:
GIT_STRATEGY: none
DEPLOY_NETWORK: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_NAME: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
DEPLOY_PORT: $REVIEW_PORT
script:
- docker-compose -f $DEPLOY_CONFIG -p $DEPLOY_NAME down -v
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
needs: ["review srv up"]
rules:
- if: $CI_COMMIT_TAG =~ /^review-/
when: manual
sonarqube on merge request:
extends: .sonarqube
script:
- PROJECT_VERSION=$(grep -oPm1 "(?<=<version>)[^<]+" $EDT_PROJECT_DIR/src/Configuration/Configuration.mdo)
- !reference [.on_merge_request, script]
rules:
- if: $CI_MERGE_REQUEST_IID
sonarqube on tag:
extends:
- .sonarqube
- .on_tag
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
# prepare:
# stage: .pre
# before_script:
# - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_amd64 -O ./allurectl
# - chmod +x ./allurectl
# script:
# - mkdir .allure
# - ./allurectl job-run start
# artifacts:
# paths:
# - .allure
# expire_in: 1 day
# allow_failure: true
# tags:
# - udocker02
# rules:
# - if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
# .run_test:
# stage: test
# before_script:
# - Invoke-Expression '[Console]::OutputEncoding = [Text.Encoding]::Utf8'
# - Invoke-Expression '[Console]::InputEncoding = [Text.Encoding]::Utf8'
# - chcp
# # - Invoke-WebRequest https://github.com/Pr-Mex/vanessa-automation/releases/download/$VA_VERSION/vanessa-automation-single.$VA_VERSION.zip -OutFile $VA
# - Start-Process -FilePath "oscript" -ArgumentList ".\tools\onescript\Compile.os .\features\" -NoNewWindow -Wait
# script:
# - Start-Process -FilePath $PLATFORM_1C -ArgumentList "CREATEINFOBASE File=$IB /Out $LOG_GREATE" -NoNewWindow -Wait
# - Start-Process -FilePath $PLATFORM_1C -ArgumentList "DESIGNER /F $IB /LoadConfigFromFiles xml /Out $LOG_UPDATE /UpdateDBCfg /DisableStartupMessages /DisableStartupDialogs" -NoNewWindow -Wait
# - Start-Process -FilePath $CLIENT_1C -ArgumentList "ENTERPRISE /F $IB /Execute $INIT_DB_LOCAL /C file=tools/users.json /Out $LOG_USER_INIT /DisableStartupMessages /DisableStartupDialogs" -NoNewWindow -Wait
# - Start-Process -FilePath $CLIENT_1C -ArgumentList "ENTERPRISE /F $IB /NАдминистратор /TestManager /Execute $VA /C`"StartFeaturePlayer;ClearCacheSteps;QuietInstallVanessaExt;VAParams=$VA_PARAMS_PATH;WorkspaceRoot=$CI_PROJECT_DIR`" /DisableStartupMessages /DisableStartupDialogs" -NoNewWindow -Wait
# artifacts:
# paths:
# - $ALLURE_RESULTS
# - ./*.log
# expire_in: 7 day
# when: always
# tags:
# - std-dtrm08
# run unit test:
# extends: .run_test
# variables:
# IB: "build/unit"
# LOG_GREATE: "unit-create.log"
# LOG_UPDATE: "unit-update.log"
# LOG_USER_INIT: "unit-user-init.log"
# VA_PARAMS_PATH: "tools/VAParams.json"
# rules:
# - if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/
# # run func test:
# # extends: .run_test
# # variables:
# # IB: "build/func"
# # LOG_GREATE: "func-create.log"
# # LOG_UPDATE: "func-update.log"
# # LOG_USER_INIT: "func-user-init.log"
# # VA_PARAMS_PATH: "tools/va/func.json"
# post:
# stage: .post
# before_script:
# - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_amd64 -O ./allurectl
# - chmod +x ./allurectl
# script:
# - ./allurectl upload $ALLURE_RESULTS
# variables:
# ALLURE_JOB_RUN_CHILD: "true"
# tags:
# - udocker02
# rules:
# - if: $CI_COMMIT_TAG =~ /^v\d+./ || $CI_COMMIT_TAG =~ /^review-/