-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.gitlab-ci.yml
168 lines (157 loc) · 5.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
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
variables:
BUILD_HELPERS_VERSION: cad23b57db14b7676808fa645c4561bc66c3e204
VIRTER_VERSION: v0.27.0
VMSHED_VERSION: v0.22.0
# we have to change the way GitLab CI clones the repository.
# by default, it is shallow, which gives us a wrong commit count when
# we do `git rev-list --count origin/master` below.
GIT_DEPTH: 0
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: normal
stages:
- base-image
- build
- package
- test
build:
stage: build
image: golang:1.23-bookworm
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == "master"
script:
- GOPATH=$(pwd)/.mygo make linstor-gateway
- GOPATH=$(pwd)/.mygo make vendor
artifacts:
paths:
- linstor-gateway
- vendor
expire_in: 3 months
.setup-lbbuild:
before_script:
- . gitlab-utils.sh
- ci_prepare_tools
- ci_fetch_lbbuildctl
- |
gateway_build() {
local version="$1"
local release="$2"
set -x
make VERSION=$version FORCE=1 debrelease
curl -isSf -u $LINBIT_REGISTRY_USER:$LINBIT_REGISTRY_PASSWORD --upload-file linstor-gateway-$version.tar.gz $LINBIT_REGISTRY_URL/repository/lbbuild-upstream/
lbbuildctl build linstor-gateway --ci \
--arch amd64 -v "$version" \
-e LINBIT_REGISTRY_USER=$LINBIT_REGISTRY_USER \
-e LINBIT_REGISTRY_PASSWORD=$LINBIT_REGISTRY_PASSWORD \
-e LINBIT_REGISTRY_URL=$LINBIT_REGISTRY_URL \
-d rhel9.0
}
package:
stage: package
extends: [ .setup-lbbuild ]
image: $LINBIT_DOCKER_REGISTRY/build-helpers:$BUILD_HELPERS_VERSION
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == "master"
script:
- if [ -n "$CI_COMMIT_TAG" ]; then
- VERSION=$(echo $CI_COMMIT_TAG | tr -d 'v')
- RELEASE=1
- else
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then
- VERSION=0.0.0.latest
- RELEASE=$(git rev-list --count "origin/$CI_COMMIT_BRANCH")
- else
- VERSION=0.0.0.$CI_COMMIT_SHA
- RELEASE=1
- fi
- dummy-release.sh linstor-gateway $VERSION $RELEASE linstor-gateway.spec
- fi
- touch --no-create vendor # Make sure we don't re-vendor
- gateway_build $VERSION $RELEASE
dependencies:
- build
base-image:
stage: base-image
rules:
- if: $CI_MERGE_REQUEST_ID
when: manual
- if: $CI_COMMIT_BRANCH == 'master'
when: manual
tags:
- libvirt
# avoid blocking the pipeline with a manual job
allow_failure: true
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- |
curl -sSfL -u gitlab-ci-token:$CI_JOB_TOKEN $CI_SERVER_URL/linbit/build-helpers/-/archive/$BUILD_HELPERS_VERSION/ignored.tar.gz | tar -xzf -
mv build-helpers-* build-helpers
. build-helpers/gitlab-utils.sh
- |
ci_prepare_tools
ci_fetch_binary virter virter-$VIRTER_VERSION https://github.com/LINBIT/virter/releases/download/$VIRTER_VERSION/virter-linux-amd64
- |
virter image rm gateway-base-image
cd integration-tests
make BASE_IMAGE=$LINBIT_DOCKER_REGISTRY/linstor-gateway-tests/base:alma-9 base_image
virter image push $LINBIT_DOCKER_REGISTRY/linstor-gateway-tests/base:alma-9
publish-docker:
stage: package
rules:
- if: $CI_MERGE_REQUEST_ID
tags:
- shell
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- |
cd integration-tests
docker build -t $LINBIT_DOCKER_REGISTRY/linstor-gateway-e2e:$CI_COMMIT_SHA .
docker push $LINBIT_DOCKER_REGISTRY/linstor-gateway-e2e:$CI_COMMIT_SHA
test:
stage: test
image: golang:1.23-bookworm
rules:
- if: $CI_MERGE_REQUEST_ID
cache:
paths:
- .mygo/pkg/mod
script:
- GOPATH=$(pwd)/.mygo go test -coverprofile .testCoverage.txt ./...
- GOPATH=$(pwd)/.mygo go tool cover -func=.testCoverage.txt
needs: [ ]
test-e2e:
stage: test
rules:
- if: $CI_MERGE_REQUEST_ID
tags:
- libvirt
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- |
curl -sSfL -u gitlab-ci-token:$CI_JOB_TOKEN https://gitlab.at.linbit.com/linbit/build-helpers/-/archive/$BUILD_HELPERS_VERSION/ignored.tar.gz | tar -xzf -
mv build-helpers-* build-helpers
. build-helpers/gitlab-utils.sh
- |
ci_prepare_tools
ci_fetch_binary virter virter-$VIRTER_VERSION https://github.com/LINBIT/virter/releases/download/$VIRTER_VERSION/virter-linux-amd64
ci_fetch_binary vmshed vmshed-$VMSHED_VERSION https://github.com/LINBIT/vmshed/releases/download/$VMSHED_VERSION/vmshed-linux-amd64
- virter image pull $LINBIT_DOCKER_REGISTRY/linstor-gateway-tests/base:alma-9
- docker pull $LINBIT_DOCKER_REGISTRY/linstor-gateway-e2e:latest
- |
cd integration-tests
make LINSTOR_GATEWAY_VERSION=0.0.0.$CI_COMMIT_SHA TEST_SUITE_IMAGE=$LINBIT_DOCKER_REGISTRY/linstor-gateway-e2e:$CI_COMMIT_SHA run
needs:
- package
- publish-docker
artifacts:
# provide a convenient name so that the downloaded artifacts can be identified
name: $CI_PROJECT_NAME-$CI_JOB_ID
paths:
- integration-tests/tests-out/
when: always
reports:
junit: integration-tests/tests-out/test-results/*.xml
expire_in: 1 week