forked from LINBIT/virter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
154 lines (143 loc) · 4.64 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
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
- if: $CI_PIPELINE_SOURCE == 'schedule'
stages:
- build
- test
- deploy
variables:
VMSHED_VERSION: v0.22.1
GO_VERSION: "1.21"
BUILD_HELPERS_VERSION: cad23b57db14b7676808fa645c4561bc66c3e204
prepare-bins:
stage: build
rules:
- if: $CI_MERGE_REQUEST_ID
image: ${LINBIT_DOCKER_REGISTRY}/build-helpers:${BUILD_HELPERS_VERSION}
script:
- . /usr/local/bin/gitlab-utils.sh
- ci_prepare_tools
- ci_fetch_binary vmshed vmshed-$VMSHED_VERSION https://github.com/LINBIT/vmshed/releases/download/$VMSHED_VERSION/vmshed-linux-amd64
cache:
key: $BUILD_HELPERS_VERSION-$VMSHED_VERSION
paths:
- download
artifacts:
paths:
- download
- bin
prepare-docker:
stage: build
rules:
- if: $CI_MERGE_REQUEST_ID
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
script:
- set -ex
- mkdir -p /kaniko/.docker
- ln -snf "$DOCKER_AUTH_CONFIG_FILE" /kaniko/.docker/config.json
- /kaniko/executor --registry-mirror $DOCKER_REGISTRY_MIRROR --dockerfile $CI_PROJECT_DIR/tests/Dockerfile --context $CI_PROJECT_DIR/tests --cache --destination ${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG
build:
image: golang:$GO_VERSION
stage: build
variables:
GOPATH: $CI_PROJECT_DIR/.mygo
script:
- go build
artifacts:
paths:
- virter
expire_in: 1 week
test:
stage: test
rules:
- if: $CI_MERGE_REQUEST_ID
image: golang:$GO_VERSION
cache:
paths:
- .mygo/pkg/mod
variables:
GOPATH: $CI_PROJECT_DIR/.mygo
script:
- go generate ./...
- go test -v -coverprofile .testCoverage.txt -covermode count ./... 2>&1 | go run github.com/jstemmer/go-junit-report@latest -set-exit-code > test.xml
- go run github.com/boumenot/gocover-cobertura@latest < .testCoverage.txt > coverage.xml
- go tool cover -func=.testCoverage.txt
coverage: '/total:\s*\(statements\)\s*\d+.\d+%/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: test.xml
lint:
stage: test
rules:
- if: $CI_MERGE_REQUEST_ID
image: golangci/golangci-lint:v1.59
variables:
GOPATH: $CI_PROJECT_DIR/.mygo
script:
- go generate ./...
- golangci-lint version
- echo "Linting new code relative to branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- golangci-lint run --new-from-rev="remotes/origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" --out-format="junit-xml" > lint.xml
allow_failure: true
artifacts:
reports:
junit:
- lint.xml
e2e-test:
stage: test
variables:
# amazonlinux: times out because it starts updates on boot
# centos-6: repos offline
# centos-8: repos offline
# debian-9: no longer supported, and cloud-init so old it crashes when a network-config is provided
# rocky-8: requires "--secure-boot=true" but we do not yet have a way of specifying that
# rocky-9: requires "--secure-boot=true" but we do not yet have a way of specifying that
EXCLUDED: amazonlinux-2|centos-6|centos-8|debian-9|rocky-8|rocky-9
rules:
- if: $CI_MERGE_REQUEST_ID
tags:
- libvirt
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- docker pull ${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG
- cp virter bin/virter
- export "PATH=$PWD/bin:$PATH"
- virter registry update
- cd tests/
- EXCLUDED_BASE_IMAGES=$EXCLUDED PULL_LOCATION=${LINBIT_DOCKER_REGISTRY}/vm ./all-base-images.sh > vms.toml
- vmshed --set values.ContainerImage=${LINBIT_DOCKER_REGISTRY}/virter/ssh:$CI_COMMIT_REF_SLUG --nvms ${LINBIT_CI_MAX_CPUS:-20}
artifacts:
when: always
paths:
- tests/tests-out/
reports:
junit:
# These reports are created by vmshed, reporting if the test command itself succeeded.
- tests/tests-out/test-results/*.xml
sync-images:
stage: deploy
timeout: 2h
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_MERGE_REQUEST_ID
when: manual
allow_failure: true
tags:
- libvirt
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- ./virter registry update
- EXIT=0
- while read name url; do
- ./virter image pull "$name" "$url" || { EXIT=1 ; echo "Failed to pull $name from $url" >&2 ; continue ; }
- ./virter image push $name ${LINBIT_DOCKER_REGISTRY}/vm/${name}:latest || { EXIT=1 ; echo "Failed to push $name to ${LINBIT_DOCKER_REGISTRY}/vm/${name}:latest" >&2 ; }
- done < <(./virter image ls --available | tail -n +2)
- exit $EXIT