.gitlab-ci.yml 9.26 KB
Newer Older
1
image: frolvlad/alpine-glibc
2

3 4 5
variables:
  DOCKERHUB_USERNAME: deichman

6
.before_script: &before
Arnljot Arntsen's avatar
Arnljot Arntsen committed
7
  - echo -n "START :" && date -u +'%Y-%m-%dT%H:%M:%SZ'
8
  - apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing make docker curl bash git
9
  - curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
10
  - chmod +x /usr/local/bin/docker-compose
11 12 13 14 15 16
  - echo $DOCKERHUB_PASSWORD|docker login -u $DOCKERHUB_USERNAME --password-stdin
.after_script: &after
  - echo -n "END :" && date -u +'%Y-%m-%dT%H:%M:%SZ'

before_script:
  - *before
Arnljot Arntsen's avatar
Arnljot Arntsen committed
17 18

after_script:
19
  - *after
20 21 22

stages:
  - build
23
  - test
Mattias Lundmark's avatar
Mattias Lundmark committed
24
  - push
25
  - deploy-test
26
  - sanity
27
  - deploy-stage
28

29 30 31 32 33 34 35

#Building

.build-application:
  script:
    - echo -n "Building ${APPLICATION_NAME}"
    - make build-${APPLICATION_NAME}
36
  stage: build
37 38 39 40 41 42 43 44 45 46 47 48 49
  only:
    changes:
      - Makefile
      - ${APPLICATION_NAME}/**/*
      - .gitlab-ci.yml
      - /*.sh
      - docker-compose.yml

build-authorization-server:
  variables:
    APPLICATION_NAME: authorization-server
  extends:
    - .build-application
50

51
build-deichman.no:
52 53 54 55
  variables:
    APPLICATION_NAME: deichman.no
  extends:
    - .build-application
56

57
build-elasticsearch:
58 59 60 61
  variables:
    APPLICATION_NAME: elasticsearch
  extends:
    - .build-application
62 63

build-euler:
64 65 66 67
  variables:
    APPLICATION_NAME: euler
  extends:
    - .build-application
68

69 70 71 72 73 74
build-f-users:
  variables:
    APPLICATION_NAME: f-users
  extends:
    - .build-application

75
build-image-api:
76 77 78 79
  variables:
    APPLICATION_NAME: image-api
  extends:
    - .build-application
80

81
build-katalog:
82 83 84 85
  variables:
    APPLICATION_NAME: katalog
  extends:
    - .build-application
Arnljot Arntsen's avatar
Arnljot Arntsen committed
86

87
build-kibana:
88 89 90 91
  variables:
    APPLICATION_NAME: kibana
  extends:
    - .build-application
92

93
build-koha:
94 95 96 97
  variables:
    APPLICATION_NAME: koha
  extends:
    - .build-application
Mattias Lundmark's avatar
Mattias Lundmark committed
98

Magnus Westergaard's avatar
Magnus Westergaard committed
99
build-mimir:
100 101 102 103
  variables:
    APPLICATION_NAME: mimir
  extends:
    - .build-application
Magnus Westergaard's avatar
Magnus Westergaard committed
104

105
build-redia-api:
106 107 108 109
  variables:
    APPLICATION_NAME: redia-api
  extends:
    - .build-application
110

Magnus Westergaard's avatar
Magnus Westergaard committed
111
build-sibyl:
112 113 114 115
  variables:
    APPLICATION_NAME: sibyl
  extends:
    - .build-application
Magnus Westergaard's avatar
Magnus Westergaard committed
116

117
build-test-ldap:
118 119 120 121
  variables:
    APPLICATION_NAME: test-ldap
  extends:
    - .build-application
122

123
build-tjenestekatalog:
124 125 126 127
  variables:
    APPLICATION_NAME: tjenestekatalog
  extends:
    - .build-application
128

129

130 131 132
#Deployment
.deploy-scp:

133
  before_script:
134
    - *before
135 136 137
    - apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing make curl bash git
    - 'which ssh-agent || ( apk add --update --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing openssh-client git )'
    - eval $(ssh-agent -s)
138
    - echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
139 140
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
141
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
142
    - chmod 644 ~/.ssh/known_hosts
143 144 145
    - export APPLICATION_NAME=${APPLICATION_NAME}
  script:
    - make remote-deploy ssh_user=${SSH_USER} ssh_servers="${SSH_SERVERS}" job_id=${CI_JOB_ID} deploy_tag=${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA:-latest}} CONTAINER=${APPLICATION_NAME}
146 147
  when: manual

148 149 150 151 152 153 154 155 156 157
#Deploy test
.devtest:
  stage: deploy-test
  environment: test
  variables:
    SSH_USER: $DEPLOY_USER
    SSH_SERVERS: $DEVTEST_SERVER
    SSH_KNOWN_HOSTS: $DEVTEST_KNOWN_HOSTS
    SSH_KEY: $DEPLOY_KEY

158

159
deploy-scheduled-test:
160 161 162
  extends:
    - .devtest
    - .deploy-scp
163
  after_script:
164 165
    - ./transitionIssues.sh test
    - *after
166 167 168
  only:
    variables:
      - $BUILD_TYPE == "scheduled"
169
  when: on_success
170

171
deploy-all-test:
172 173 174
  extends:
    - .devtest
    - .deploy-scp
175
  after_script:
176 177
    - ./transitionIssues.sh test
    - *after
178 179
  when: manual

180 181 182 183 184 185 186 187
.only-app-changes:
  only:
    changes:
      - ${APPLICATION_NAME}/**/*
      - .gitlab-ci.yml
      - Makefile
      - /*.sh
      - docker-compose.yml
188

189
deploy-authorization-server-test:
190 191 192 193
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
194 195 196
  variables:
    APPLICATION_NAME: authorization-server

197
deploy-deichman_no-test:
198 199 200 201
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
202 203 204
  variables:
    APPLICATION_NAME: deichman.no

205
deploy-elasticsearch-test:
206 207 208 209
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
210 211 212
  variables:
    APPLICATION_NAME: elasticsearch

213
deploy-euler-test:
214 215 216 217
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
218 219 220
  variables:
    APPLICATION_NAME: euler

221 222 223 224 225 226 227 228
deploy-f-users-test:
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
  variables:
    APPLICATION_NAME: f-users

229
deploy-image-api-test:
230 231 232 233
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
234 235 236
  variables:
    APPLICATION_NAME: image-api

237
deploy-katalog-test:
238 239 240 241
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
242 243 244
  variables:
    APPLICATION_NAME: katalog

245
deploy-kibana-test:
246 247 248 249
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
250 251
  variables:
    APPLICATION_NAME: kibana
252

253
deploy-koha-test:
254 255 256 257
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
258 259 260
  variables:
    APPLICATION_NAME: koha

261
deploy-mimir-test:
262 263 264 265
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
266 267 268
  variables:
    APPLICATION_NAME: mimir

269
deploy-redia-api-test:
270 271 272 273
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
274 275 276
  variables:
    APPLICATION_NAME: redia-api

277
deploy-sibyl-test:
278 279 280 281
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
282 283 284
  variables:
    APPLICATION_NAME: sibyl

285
deploy-test-ldap-test:
286 287 288 289
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
290 291
  variables:
    APPLICATION_NAME: test-ldap
292

293
deploy-tjenestekatalog-test:
294 295 296 297
  extends:
    - .only-app-changes
    - .devtest
    - .deploy-scp
Magnus Westergaard's avatar
Magnus Westergaard committed
298 299
  variables:
    APPLICATION_NAME: tjenestekatalog
300

301 302 303 304 305 306 307 308 309 310 311
#Deploy staging

.staging:
  stage: deploy-stage
  environment: stage
  variables:
    SSH_USER: $DEPLOY_USER
    SSH_KNOWN_HOSTS: $STAGING_HOSTS
    SSH_SERVERS: "${STAGING_SERVERS}"
    SSH_KEY: $DEPLOY_KEY

312
deploy-all-staging:
313 314 315 316 317 318
  extends:
    - .staging
    - .deploy-scp
  only:
    refs:
      - tags
319 320 321 322
  when: manual
  after_script:
    - ./transitionIssues.sh stage
    - *after
323

324
#Automated tests
325
koha-api-tests:
326 327 328 329
  variables:
    APPLICATION_NAME: koha
  extends:
    - .only-app-changes
330
  tags:
331
    - koha
332 333
  script:
    - cd koha/tests
334
    - make KOHA_API=http://koha-test-1.t.obib.no/api build run-ci
335
  stage: sanity
336 337
  when: on_success

338
.e2e-tests:
Magnus Westergaard's avatar
Magnus Westergaard committed
339 340
  tags:
    - e2e
Magnus Westergaard's avatar
Magnus Westergaard committed
341
  script:
342
    - cd e2e-tests
Magnus Westergaard's avatar
Magnus Westergaard committed
343
    - docker-compose -p $CI_PIPELINE_IID -f docker-compose-common.yml -f docker-compose-ci.yml up --build --exit-code-from tests
Magnus Westergaard's avatar
Magnus Westergaard committed
344
  after_script:
345
    - cd e2e-tests
346
    - docker-compose -p $CI_PIPELINE_IID -f docker-compose-common.yml -f docker-compose-ci.yml down -v --rmi local
Arnljot Arntsen's avatar
Arnljot Arntsen committed
347
    - echo -n "END :" && date -u +'%Y-%m-%dT%H:%M:%SZ'
Magnus Westergaard's avatar
Magnus Westergaard committed
348
  artifacts:
349
    when: always
Magnus Westergaard's avatar
Magnus Westergaard committed
350 351
    expire_in: 1 week
    paths:
352 353
      - e2e-tests/cypress/videos/
      - e2e-tests/cypress/screenshots/
354
  stage: test
Magnus Westergaard's avatar
Magnus Westergaard committed
355
  only:
Tommy Svendsen's avatar
Tommy Svendsen committed
356 357
    refs:
      - schedules
358
  when: on_success
359 360 361 362 363
#
## Push stages here
.push:
  script:
    - make push-${APPLICATION_NAME} TAG=${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}}
Mattias Lundmark's avatar
Mattias Lundmark committed
364
  stage: push
Mattias Lundmark's avatar
Mattias Lundmark committed
365
  when: manual
Mattias Lundmark's avatar
Mattias Lundmark committed
366

367 368 369
push-all:
  script:
    - make push-all TAG=${CI_COMMIT_TAG:-${CI_COMMIT_SHORT_SHA}}
370 371
  stage: push
  only:
372 373
    refs:
      - tags
374

375 376 377 378 379 380 381 382
#push-all-latest:
#  script:
#    - make push-all TAG=${CI_COMMIT_SHORT_SHA}
#  stage: push
#  only:
#    variables:
#      - $BUILD_TYPE == "scheduled"
#  when: on_success
383

384
push-all-latest-manual:
385 386
  script:
    - make push-all TAG=${CI_COMMIT_SHORT_SHA}
387 388 389
  stage: push
  when: manual

390 391 392 393 394
push-authorization-server:
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
395 396 397 398
  variables:
    APPLICATION_NAME: authorization-server


399
push-deichman.no-latest:
400 401 402 403
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
404 405
  variables:
    APPLICATION_NAME: deichman.no
Mattias Lundmark's avatar
Mattias Lundmark committed
406

407
push-elasticsearch-latest:
408 409 410 411
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
412 413
  variables:
    APPLICATION_NAME: elasticsearch
Mattias Lundmark's avatar
Mattias Lundmark committed
414 415

push-euler-latest:
416 417 418 419
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
420 421
  variables:
    APPLICATION_NAME: euler
Mattias Lundmark's avatar
Mattias Lundmark committed
422

423 424 425 426 427 428 429 430
push-f-users-latest:
  extends:
    - .only-app-changes
    - .push
  when: on_success
  variables:
    APPLICATION_NAME: f-users

431
push-image-api-latest:
432 433 434 435
  extends:
    - .only-app-changes
    - .push
  when: on_success
436 437 438
  variables:
    APPLICATION_NAME: image-api

Mattias Lundmark's avatar
Mattias Lundmark committed
439
push-katalog-latest:
440 441 442 443
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
444 445
  variables:
    APPLICATION_NAME: katalog
Mattias Lundmark's avatar
Mattias Lundmark committed
446

447
push-kibana-latest:
448 449 450 451
  extends:
    - .only-app-changes
    - .push
  when: on_success
452 453
  variables:
    APPLICATION_NAME: kibana
Magnus Westergaard's avatar
Magnus Westergaard committed
454

455
push-koha-latest:
456 457 458 459
  extends:
    - .only-app-changes
    - .push
  when: on_success
460 461
  variables:
    APPLICATION_NAME: koha
462
push-mimir-latest:
463 464 465 466
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
467 468
  variables:
    APPLICATION_NAME: mimir
469
push-redia-api-latest:
470 471 472 473
  extends:
    - .only-app-changes
    - .push
  when: on_success
474 475
  variables:
    APPLICATION_NAME: redia-api
476
push-sibyl-latest:
477 478 479 480
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
481 482
  variables:
    APPLICATION_NAME: sibyl
483

484
push-test-ldap-latest:
485 486 487 488
  extends:
    - .only-app-changes
    - .push
  when: on_success
489 490
  variables:
    APPLICATION_NAME: test-ldap
491

492
push-tjenestekatalog-latest:
493 494 495 496
  extends:
    - .only-app-changes
    - .push
  when: on_success
Magnus Westergaard's avatar
Magnus Westergaard committed
497 498
  variables:
    APPLICATION_NAME: tjenestekatalog