This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
106 lines (97 loc) · 4.17 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
image: docker:20
services:
- docker:20-dind
variables:
DOCKER_BUILDKIT: 0
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
HOST_IP: 172.99.0.1
before_script:
- echo "$DOCKER_REGISTRY_TOKEN" | docker login --username "$DOCKER_REGISTRY_USER" --password-stdin
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
prometheus_build:
stage: ci_build
script:
- cd docker/prometheus
- docker build -t $CI_REGISTRY_IMAGE:prometheus .
- docker push $CI_REGISTRY_IMAGE:prometheus
when: manual
testrunner_build:
stage: ci_build
script:
- cd test
- docker build -t registry.gitlab.com/ontola/argu:base-pw .
- docker push registry.gitlab.com/ontola/argu:base-pw
when: manual
libro_build:
stage: build
image: docker:18.09.8
services:
- docker:18.09.8-dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
script:
- apk add git
- LIBRO_CLIENT_TAG=$(git submodule status --cached services/libro-client | awk '{print $1;}' | tr -cd '[:alnum:]')
- LIBRO_SERVER_TAG=$(git submodule status --cached services/libro-server | awk '{print $1;}' | tr -cd '[:alnum:]')
- echo $LIBRO_CLIENT_TAG
- echo $LIBRO_SERVER_TAG
- docker build --tag $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE/libro:latest --build-arg=LIBRO_CLIENT_TAG=$LIBRO_CLIENT_TAG --build-arg=LIBRO_SERVER_TAG=$LIBRO_SERVER_TAG ./docker/libro
- docker push $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE/libro:latest
tag:
stage: tag
rules:
- if: $CI_COMMIT_TAG
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
script:
- docker pull $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE/libro:$CI_COMMIT_TAG
test:
stage: test
script:
- "[[ $CI_COMMIT_BRANCH = master ]] && RAILS_ENV=production || RAILS_ENV=staging"
- apk add bash ca-certificates curl git openssl sudo
- echo DEFAULT_LOCALE=en >> ./.env.template
- echo DISABLE_PROMETHEUS=true >> ./.env.template
- sed -i "s/{bugsnag_key}/$BUGSNAG_KEY/g" ./.env.template
- ./bin/build_testrunner.sh
- ./bin/install.sh
- ./bin/test.sh
- timeout 5m bash -c 'until [ $(docker ps -f health=starting -q | wc -l) -eq 0 ]; do sleep 1; done'
- ./bin/initialize_db.sh
- docker-compose restart apex
- timeout 5m bash -c 'until [ $(docker ps -f health=starting -q | wc -l) -eq 0 ]; do sleep 1; done'
- docker-compose exec -T apex bundle exec rake cache:warm
- ./bin/dump_db.sh
- timeout 5m bash -c 'until [ $(docker ps -f health=starting -q | wc -l) -eq 0 ]; do sleep 1; done'
- docker ps -a
- docker images
- docker-compose exec -T libro_server cat client_version.txt
- docker-compose exec -T libro_server cat server_version.txt
- TEST_TIMEOUT=${TEST_TIMEOUT:-50m}
- echo test timeout $TEST_TIMEOUT
- timeout $TEST_TIMEOUT bash -c 'docker-compose exec testrunner sh -c "bundle exec rspec --format documentation --format RSpec::Instafail --format RspecJunitFormatter --out /tmp/test-results/rspec.xml $TEST_FILES"'
after_script:
- mkdir $CI_PROJECT_DIR/test-results || true
- docker cp argu-testrunner-1:/tmp/test-results/rspec.xml $CI_PROJECT_DIR/test-results/rspec.xml || true
- docker cp argu-testrunner-1:/usr/src/app/tmp/exceptions $CI_PROJECT_DIR/test-results/exceptions || true
- docker ps --no-trunc -a > $CI_PROJECT_DIR/test-results/docker-ps.txt || true
- docker-compose logs > $CI_PROJECT_DIR/test-results/docker-compose-logs.txt || true
- 'curl -H "Host: argu.localtest" -f http://localhost:3080/link-lib/cache/status > cache_health.txt || true'
- 'curl -H "Host: argu.localtest" -f http://localhost:3080/d/health > libro_health.txt || true'
- ls -la $CI_PROJECT_DIR/test-results
artifacts:
paths:
- test-results/
- docker-compose.yml
expire_in: 1 week
when: on_failure
stages:
- ci_build
- build
- tag
- test