-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path.gitlab-ci-check-docker-acceptance.yml
173 lines (168 loc) · 6.47 KB
/
.gitlab-ci-check-docker-acceptance.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
# .gitlab-ci-check-docker-acceptance.yml
#
# This gitlab-ci template builds, runs acceptance tests and publishes
# code coverage from a Docker based repository.
#
# It assumes the following files:
# * Dockerfile.acceptance-testing: to build the the binary with test coverage.
# * tests/Dockerfile to build the Python test runner.
# * tests/docker-compose-acceptance.yml for the tests composition runtime.
# * tests/docker-compose-acceptance-enterprise.yml (optional) for Enterprise tests.
#
# Requires DOCKER_REPOSITORY variable to be set in the calling Pipeline.
# Add it to the project in hand through Gitlab's include functionality
#
# variables:
# DOCKER_REPOSITORY: <Image FQN, i.e mendersoftware/reponame>
# INTEGRATION_REV: <integration revision> (optional, defaults to master)
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-docker-acceptance.yml'
#
# Requires the following variables set in the project CI/CD settings:
# COVERALLS_TOKEN: Token from coveralls.io for this repository
#
# If the tests require access to Mender Registry hosted images, it
# will require also the following vabiables:
# REGISTRY_MENDER_IO_USERNAME: Username for registry.mender.io
# REGISTRY_MENDER_IO_PASSWORD: Password for registry.mender.io
#
stages:
- test_prep
- test
- publish
test:prepare_acceptance:
tags:
- mender-qa-worker-generic-light
stage: test_prep
needs: []
image: docker
rules:
- if: '$CI_COMMIT_TAG =~ /^saas-[a-zA-Z0-9.]+$/'
when: never
- when: on_success
services:
- docker:20.10.21-dind
script:
- docker build -f Dockerfile.acceptance-testing -t $DOCKER_REPOSITORY:prtest .
- docker save $DOCKER_REPOSITORY:prtest > tests_image.tar
- docker build -t $DOCKER_REPOSITORY:pr .
- CONTAINER_ID=$(docker create "$DOCKER_REPOSITORY:pr")
- docker cp "$CONTAINER_ID:/usr/bin/${CI_PROJECT_NAME}" "$(pwd)"
- docker rm "$CONTAINER_ID"
# Repos using common tester image might not have the Dockerfile
- if [ -f tests/Dockerfile ]; then
- docker build -t testing -f tests/Dockerfile tests
- docker save testing > acceptance_testing_image.tar
- fi
- wget https://downloads.mender.io/mender-artifact/master/linux/mender-artifact
- chmod +x mender-artifact
artifacts:
expire_in: 2w
paths:
- '*_image.tar'
- ${CI_PROJECT_NAME}
- mender-artifact
test:acceptance_tests:
tags:
- mender-qa-worker-generic-light
stage: test
needs:
- job: test:prepare_acceptance
artifacts: true
rules:
- if: '$CI_COMMIT_TAG =~ /^saas-[a-zA-Z0-9.]+$/'
when: never
- when: on_success
image: tiangolo/docker-with-compose
services:
- docker:20.10.21-dind
before_script:
- apk add git bash
- git clone -b ${INTEGRATION_REV:-master} --depth=1 https://github.com/mendersoftware/integration.git mender-integration
- mv mender-integration/extra/travis-testing/* tests/
- mv docs/* tests/
- mv ${CI_PROJECT_NAME} tests/
- mv mender-artifact tests/
- if [ -f keys/private.pem ]; then
- mv keys/private.pem tests/
- fi
- docker load -i tests_image.tar
# Repos using common tester image might not have the Dockerfile
- if [ -f tests/Dockerfile ]; then
- docker load -i acceptance_testing_image.tar
- fi
- if [ -n "$REGISTRY_MENDER_IO_USERNAME" ]; then
- docker login -u "$REGISTRY_MENDER_IO_USERNAME" -p "$REGISTRY_MENDER_IO_PASSWORD" registry.mender.io
- fi
- if [ -n "$MENDER_TEST_CONTAINERS_CANDIDATE_TAG" ]; then
- sed -i.bak -e "s,mendersoftware/mender-test-containers:acceptance-testing,$MENDER_TEST_CONTAINERS_CANDIDATE_TAG," tests/docker-compose-acceptance.yml
- diff -u tests/docker-compose-acceptance.yml.bak tests/docker-compose-acceptance.yml || true
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- fi
script:
- TESTS_DIR=$(pwd)/tests $(pwd)/tests/run-test-environment acceptance $(pwd)/mender-integration $(pwd)/tests/docker-compose-acceptance.yml
- if [ -f $(pwd)/tests/docker-compose-acceptance-enterprise.yml ]; then
- mv tests/coverage-acceptance.txt cover.prof
- TESTS_DIR=$(pwd)/tests $(pwd)/tests/run-test-environment acceptance $(pwd)/mender-integration $(pwd)/tests/docker-compose-acceptance-enterprise.yml
# Merge the test coverage from open-source and enterprise runs
- mv tests/coverage-acceptance.txt cover-ent.prof
- tail -n +2 cover-ent.prof | cat cover.prof - > tests/coverage-acceptance.txt
- fi
artifacts:
expire_in: 2w
paths:
- tests/acceptance.*
- tests/coverage-acceptance.txt
reports:
junit: tests/results.xml
when: always
publish:acceptance:
tags:
- mender-qa-worker-generic-light
stage: publish
needs:
- job: test:acceptance_tests
artifacts: true
rules:
- if: '$CI_COMMIT_TAG =~ /^saas-[a-zA-Z0-9.]+$/'
when: never
- when: on_success
image: golang:1.20-alpine3.17
before_script:
# Install dependencies
- apk add --no-cache git
- go install github.com/mattn/goveralls@latest
# Prepare GOPATH
- mkdir -p /go/src/github.com/mendersoftware
- cp -r ${CI_PROJECT_DIR} /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
- cd /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
# Coveralls env variables:
# According to https://docs.coveralls.io/supported-ci-services
# we should set CI_NAME, CI_BUILD_NUMBER, etc. But according
# to goveralls source code (https://github.com/mattn/goveralls)
# many of these are not supported. Set CI_BRANCH
# and pass few others as command line arguments.
# See also https://docs.coveralls.io/api-reference
- export CI_BRANCH=${CI_COMMIT_BRANCH}
script:
- goveralls
-repotoken ${COVERALLS_TOKEN}
-service gitlab-ci
-jobid $CI_PIPELINE_ID
-covermode set
-flagname acceptance
-parallel
-coverprofile ./tests/coverage-acceptance.txt
coveralls:finish-build:
tags:
- mender-qa-worker-generic-light
stage: .post
# See https://docs.coveralls.io/parallel-build-webhook
variables:
COVERALLS_WEBHOOK_URL: "https://coveralls.io/webhook"
COVERALLS_RERUN_BUILD_URL: "https://coveralls.io/rerun_build"
image: curlimages/curl-base
script:
- 'curl -k ${COVERALLS_WEBHOOK_URL}?repo_token=${COVERALLS_TOKEN} -d "payload[build_num]=$CI_PIPELINE_ID&payload[status]=done"'
- 'curl -k "${COVERALLS_RERUN_BUILD_URL}?repo_token=${COVERALLS_TOKEN}&build_num=${CI_PIPELINE_ID}"'