-
Notifications
You must be signed in to change notification settings - Fork 57
/
.gitlab-ci.yml
405 lines (383 loc) · 13.3 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
---
# https://docs.gitlab.com/ee/ci/yaml/index.html#switch-between-branch-pipelines-and-merge-request-pipelines
workflow:
rules:
- if: $CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_OPEN_MERGE_REQUESTS || $CI_COMMIT_TAG
when: never
- when: always
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker
variables:
# When you use the dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket. Docker 19.03 does this automatically
# by setting the DOCKER_HOST in
# https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/services/#accessing-the-services.
#
# Specify to Docker where to create the certificates. Docker
# creates them automatically on boot, and creates
# `/certs/client` to share between the service and job
# container, thanks to volume mount from config.toml
DOCKER_HOST: tcp://docker:2376
DOCKER_VERSION: "23"
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: 1
default:
retry: 1
cache: &global_cache
- key:
files:
- go.mod
- go.sum
paths:
- /go/pkg/mod
- key:
files:
- frontend/package.json
- frontend/bun.lockb
paths:
- frontend/node_modules
- key:
files:
- old-frontend/package.json
- old-frontend/yarn.lock
paths:
- old-frontend/node_modules
- key:
files:
- e2e/package.json
- e2e/yarn.lock
paths:
- e2e/node_modules
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
stages:
- lint
- build-codegen
- generate
- unit-test
- build
- build-no-cache
- test
- release
- container-scan
commit-lint:
stage: lint
image: node:lts
before_script:
- npm install -g [email protected] @commitlint/[email protected]
script:
- git fetch https://gitlab.com/isard/isardvdi.git main
- commitlint --from=$(git merge-base HEAD FETCH_HEAD)
version:
stage: lint
image: node:lts
rules:
# semantic-release checks repository write access and we cannot use
# GITLAB_TOKEN in unprotected branches due to security reasons.
# https://github.com/semantic-release/semantic-release/issues/2207
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
before_script:
- npm install -g semantic-release@23 @semantic-release/exec @semantic-release/gitlab conventional-changelog-conventionalcommits@6
script:
- semantic-release --dry-run --branches $CI_COMMIT_REF_NAME
artifacts:
paths:
- .VERSION
check-python:
stage: lint
image: python:3.10-bullseye
script:
- pip install isort black==24.3.0
- isort --check .
- black --check .
check-frontend:
stage: lint
image: oven/bun:1.1.24-alpine
parallel:
matrix:
- JOB: "format --write=false --check"
- JOB: "lint"
# TODO: Remove this when all lint errors are fixed
ALLOW_FAILURE: "true"
# - JOB: "type-check"
# # TODO: Remove this when all type errors are fixed
# ALLOW_FAILURE: "true"
rules:
- if: $ALLOW_FAILURE == "true"
allow_failure: true
- if: $ALLOW_FAILURE != "true"
allow_failure: false
script:
- cd frontend
- bun install --frozen-lockfile
- bun run $JOB
check-old-frontend:
stage: lint
image: node:18.17
script:
- cd old-frontend
- yarn install --frozen-lockfile
- yarn lint --no-fix --max-warnings 0
check-protobuf:
stage: lint
image:
name: bufbuild/buf:1.44.0
entrypoint: [""]
script:
- buf lint
- buf breaking --against https://gitlab.com/isard/isardvdi.git
docker-image-codegen:
image: "docker:${DOCKER_VERSION}"
stage: build-codegen
services:
- name: "docker:${DOCKER_VERSION}-dind-rootless"
parallel:
matrix:
- DOCKERFILE: docker/codegen/Dockerfile
IMAGE: codegen
before_script:
- until docker info; do sleep 1; done
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -f $DOCKERFILE --cache-from registry.gitlab.com/isard/isardvdi/$IMAGE:main --cache-to type=inline -t $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG .
- docker tag $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
docker-image-codegen-no-cache:
image: "docker:${DOCKER_VERSION}"
stage: build-codegen
services:
- name: "docker:${DOCKER_VERSION}-dind-rootless"
parallel:
matrix:
- DOCKERFILE: docker/codegen/Dockerfile
IMAGE: codegen
before_script:
- until docker info; do sleep 1; done
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -f $DOCKERFILE -t $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG .
- docker tag $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
when: manual
gen-protobuf:
stage: generate
image: "docker:${DOCKER_VERSION}"
services:
- name: "docker:${DOCKER_VERSION}-dind-rootless"
before_script:
- until docker info; do sleep 1; done
script:
- docker run -u $(id -u) -v "$(pwd):/build" "$CI_REGISTRY_IMAGE/codegen:git-$CI_COMMIT_SHORT_SHA"
artifacts:
paths:
- pkg/gen
- frontend/src/gen
- "**/testing_*_mock.go"
docker-compose-build:
stage: generate
image: "docker:${DOCKER_VERSION}"
services:
- name: "docker:${DOCKER_VERSION}-dind-rootless"
before_script:
- apk add bash git docker-compose yq
script:
- cp isardvdi.cfg.example isardvdi.build.cfg
- echo "DOCKER_IMAGE_PREFIX=${CI_REGISTRY_IMAGE}/" >> isardvdi.build.cfg
- echo "DOCKER_IMAGE_TAG=$CI_COMMIT_REF_SLUG" >> isardvdi.build.cfg
- echo "USAGE=build" >> isardvdi.build.cfg
- echo "BASTION_ENABLED=true" >> isardvdi.build.cfg
- cp isardvdi.build.cfg isardvdi.infrastructure.build.cfg
- echo "INFRASTRUCTURE_MANAGEMENT=true" >> isardvdi.infrastructure.build.cfg
- cp isardvdi.build.cfg isardvdi.video-standalone.build.cfg
- echo "FLAVOUR=video-standalone" >> isardvdi.video-standalone.build.cfg
- cp isardvdi.build.cfg isardvdi.monitor.build.cfg
- echo "FLAVOUR=monitor" >> isardvdi.monitor.build.cfg
- cp isardvdi.build.cfg isardvdi.check.build.cfg
- echo "FLAVOUR=check" >> isardvdi.check.build.cfg
- cp isardvdi.build.cfg isardvdi.nextcloud.build.cfg
- echo "FLAVOUR=nextcloud" >> isardvdi.nextcloud.build.cfg
- BACKUP_DB_ENABLED=true CODEGEN=false ./build.sh
- |-
for file in docker-compose*.yml; do
cp "$file" "no-cache-$file"
yq -i '.services |= map_values(.build.cache_from = [ "registry.gitlab.com/isard/isardvdi/" + (.container_name | sub("isard-", "")) + ":main" ]) |= map_values(.build.cache_to = [ "type=inline" ])' $file
done
artifacts:
paths:
- docker-compose*.yml
- no-cache-docker-compose*.yml
unit-test-go:
stage: unit-test
image: golang:1.23
before_script:
- apt-get update && apt-get install -y libvirt-dev
- go install gotest.tools/gotestsum@latest
- go install github.com/boumenot/gocover-cobertura@latest
script:
- export PATH=$PATH:~/go/bin
- gotestsum --junitfile report.xml --format testname -- -race ./... -coverprofile coverage.out -covermode atomic
- go tool cover -func coverage.out
- gocover-cobertura < coverage.out > coverage.xml
artifacts:
when: always
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: report.xml
coverage: /total:\s+\(statements\)\s+\d+.\d+%/
docker-image:
image: "docker:${DOCKER_VERSION}"
stage: build
services:
- name: "docker:${DOCKER_VERSION}-dind-rootless"
parallel:
matrix:
- DOCKER_COMPOSE: build
IMAGE: &containers
- api
- scheduler
- authentication
- backupninja
- bastion
- core_worker
- db
- engine
- grafana
- guac
- rdpgw
- hypervisor
- notifier
- portal
- sessions
- squid
- static
- stats-go
- stats-rethinkdb
- storage
- webapp
- websockify
- DOCKER_COMPOSE: build
IMAGE_DEPENDENCY: isard-rdpgw
IMAGE: vpn
- DOCKER_COMPOSE: infrastructure.build
IMAGE: orchestrator
- DOCKER_COMPOSE: video-standalone.build
IMAGE: video
- DOCKER_COMPOSE: monitor.build
IMAGE: monitor-proxy
- DOCKER_COMPOSE: check.build
IMAGE:
- check
- check-client
- DOCKER_COMPOSE: nextcloud.build
IMAGE:
- nc-proxy
- nc-app
before_script:
- apk add git docker-compose
- until docker info; do sleep 1; done
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- git submodule update --init --recursive --remote
- echo $IMAGE_DEPENDENCY isard-$IMAGE | xargs -n1 docker-compose -f docker-compose.$DOCKER_COMPOSE.yml build
- docker tag $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
docker-image-no-cache:
extends: docker-image
stage: build-no-cache
script:
- git submodule update --init --recursive --remote
- echo $IMAGE_DEPENDENCY isard-$IMAGE | xargs -n1 docker-compose -f no-cache-docker-compose.$DOCKER_COMPOSE.yml build
- docker tag $CI_REGISTRY_IMAGE/$IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA
when: manual
# test-e2e:
# stage: test
# variables:
# DOCKER_TLS_CERTDIR: "/certs-root"
# services:
# - name: "docker:dind"
# variables:
# DOCKER_TLS_CERTDIR: "/certs-root"
# alias: docker
# image: "docker:latest"
# before_script:
# - apk add git docker-compose
# - until docker info; do sleep 1; done
# - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# - cp isardvdi.cfg.example isardvdi.e2e.cfg
# - echo "USAGE=test" >> isardvdi.e2e.cfg
# - echo "DOMAIN=host.docker.internal" >> isardvdi.e2e.cfg
# - echo "DOCKER_IMAGE_PREFIX=${CI_REGISTRY_IMAGE}/" >> isardvdi.e2e.cfg
# - echo "DOCKER_IMAGE_TAG=git-$CI_COMMIT_SHORT_SHA" >> isardvdi.e2e.cfg
# - CODEGEN=false ./build.sh
# - docker compose -f docker-compose.e2e.yml pull
# - docker compose -f docker-compose.e2e.yml up -d
# script:
# - cd frontend
# - docker run --rm -w "/frontend" -v "$PWD:/frontend" node:18 yarn
# - export PORTAL="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' isard-portal | tr -d '\n')"
# - export NETWORK="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.NetworkID}}{{end}}' isard-portal | tr -d '\n')"
# - docker run --rm --ipc=host -w "/frontend" -v "$PWD:/frontend" -e "DOCKER=true" -e "CI=true" --add-host="host.docker.internal:$PORTAL" --network="$NETWORK" mcr.microsoft.com/playwright:v1.36.0-jammy yarn playwright test
# artifacts:
# when: always
# paths:
# - frontend/test-results
# - frontend/playwright-report
gemnasium-dependency_scanning:
variables:
# Scan all the subdirectories
DS_MAX_DEPTH: -1
DS_INCLUDE_DEV_DEPENDENCIES: "false"
docker-tag:
stage: release
image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
parallel:
matrix:
- IMAGE: *containers
- IMAGE: &containers_extra
- codegen
- check
- check-client
- vpn
- orchestrator
- video
- monitor-proxy
- nc-proxy
- nc-app
script:
- test "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" -a ! -e ".VERSION" && exit 0
- crane auth login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- crane tag $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA $CI_COMMIT_REF_SLUG
- test ! -e ".VERSION" && exit 0
- crane tag $CI_REGISTRY_IMAGE/$IMAGE:git-$CI_COMMIT_SHORT_SHA v$(cat .VERSION | tr '.' '-')
release:
stage: release
image: node:lts
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- test ! -e ".VERSION" && exit 0
- 'sed -i "s/^\(\s*DOCKER_IMAGE_TAG: \)$CI_DEFAULT_BRANCH$/\1v$(cat .VERSION | tr "." "-")/" docker-compose*.yml'
- npm install -g semantic-release@23 @semantic-release/exec @semantic-release/gitlab conventional-changelog-conventionalcommits@6
- semantic-release --branches $CI_DEFAULT_BRANCH
container_scanning:
stage: container-scan
variables:
CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/$IMAGE
CI_APPLICATION_TAG: $CI_COMMIT_REF_SLUG
CS_DISABLE_LANGUAGE_VULNERABILITY_SCAN: "false"
parallel:
matrix:
- IMAGE: *containers
- IMAGE: *containers_extra