forked from picodata/tarantool-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
350 lines (323 loc) · 12 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
default:
image:
name: docker-public.binary.picodata.io/kaniko-project/executor:v1.14.0-debug
entrypoint: ['']
pull_policy: [if-not-present]
tags:
- docker-k8s
stages:
- build-base-image
- test
workflow:
# See https://docs.gitlab.com/ee/ci/jobs/job_control.html#avoid-duplicate-pipelines
rules:
# To avoid duplicate pipelines we disable merge request events,
# leaving only pushes and manual triggering.
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_PIPELINE_SOURCE == "push"
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_PIPELINE_SOURCE == "pipeline"
variables:
GIT_DEPTH: 1
GIT_STRATEGY: fetch
DOCKER_AUTH_CONFIG: $DOCKER_AUTH_RW
KANIKO_REGISTRY_MIRROR: docker-proxy.binary.picodata.io
CACHE_PATHS: target
CARGO_INCREMENTAL: 0
RUST_VERSION: "1.71" # Note: without the quotes yaml thinks this is a float and removes the trailing 0
CARGO_HOME: /shared-storage/tarantool-module/.cargo
BASE_IMAGE_VANILLA: docker-public.binary.picodata.io/tarantool-module-build-base-vanilla
BASE_IMAGE_FORK: docker-public.binary.picodata.io/tarantool-module-build-base-fork
# job:rules explained:
#
# - if build-base changes on master branch (compared to HEAD~1)
# * build-base-image-vanilla/fork (with tag latest) and push
# * test (on corresponding base-image:latest)
# - if build-base changes on development branch (compared to master)
# * build-base-image-vanilla/fork (with tag <SHA>)
# * test (on on corresponding base-image:<SHA>)
# - else (if build-base doesn't change)
# * skip build-base-image
# * just test (on existing base-image:latest)
#
# A different workflow applies on trigger (when tarantool is tagged):
# * build-base-image-fork from specified TARANTOOL_TAG (with tag <SHA>-triggered)
# * test (on base-image-fork:<SHA>-triggered)
#
# Anchor syntax explained here:
# https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html
#
.rules:
- &if-build-base-changes-on-master-branch
if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH) && ($CI_PIPELINE_SOURCE != "pipeline")
changes:
# implies compare_to HEAD~1
paths: &build-base-changes-paths
- docker/**
- .gitlab-ci.yml
- &if-build-base-changes-on-dev-branch
if: ($CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH) && ($CI_PIPELINE_SOURCE != "pipeline")
changes:
compare_to: master
paths: *build-base-changes-paths
# Если запущено через родительский downstream trigger
- &if-triggered
if: $CI_PIPELINE_SOURCE == "pipeline"
- &else {}
.docker-login: &docker-login
before_script:
- mkdir -p /kaniko/.docker
- echo "$DOCKER_AUTH_RW" > /kaniko/.docker/config.json
# Билд контейнера через kaniko
.build-base-image:
stage: build-base-image
rules:
- <<: *if-build-base-changes-on-master-branch
variables:
BASE_IMAGE_TAG: latest
PUSH_DOCKER: ""
- <<: *if-build-base-changes-on-dev-branch
variables:
BASE_IMAGE_TAG: ${CI_COMMIT_SHA}
PUSH_DOCKER: ""
- <<: *else
when: never
<<: *docker-login
script:
- |
/kaniko/executor --context $CI_PROJECT_DIR --dockerfile ${DOCKERFILE} \
--build-arg "RUST_VERSION=${RUST_VERSION}" ${EXTRA_BUILD_ARGS} ${PUSH_DOCKER} \
--cache=false --cache-run-layers=true --single-snapshot --compressed-caching=false --use-new-run --snapshot-mode=redo --cleanup \
--destination ${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}
build-base-image-vanilla:
extends: .build-base-image
variables:
BASE_IMAGE_NAME: ${BASE_IMAGE_VANILLA}
DOCKERFILE: ./docker/vanilla.Dockerfile
build-base-image-fork:
extends: .build-base-image
variables:
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
EXTRA_BUILD_ARGS: >
--build-arg TARANTOOL_TAG=latest
DOCKERFILE: ./docker/picodata.Dockerfile
build-base-image-fork-on-trigger:
extends: .build-base-image
rules: # overrides whole section from .build-base-image
- <<: *if-triggered
variables:
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
BASE_IMAGE_TAG: ${CI_COMMIT_SHA}-triggered
PUSH_DOCKER: ""
EXTRA_BUILD_ARGS: >
--build-arg TARANTOOL_TAG=${TARANTOOL_TAG}
DOCKERFILE: ./docker/picodata.Dockerfile
.test:
stage: test
rules:
- <<: *if-build-base-changes-on-master-branch
variables:
BASE_IMAGE_TAG: latest
- <<: *if-build-base-changes-on-dev-branch
variables:
BASE_IMAGE_TAG: ${CI_COMMIT_SHA}
- <<: *else
variables:
BASE_IMAGE_TAG: latest
image:
name: ${BASE_IMAGE_NAME}:${BASE_IMAGE_TAG}
pull_policy: [if-not-present]
before_script:
- |
# Restore cache
if [ -z "${CACHE_ARCHIVE}" ]; then
: # do nothing
elif [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
echo "Skip restoring cache on the master branch"
elif [ -f "${CACHE_ARCHIVE}" ]; then
ci-log-section start "restore-cache" Restoring cache from ${CACHE_ARCHIVE} ...
tar -xf ${CACHE_ARCHIVE}
du -sh ${CACHE_PATHS} || true
ci-log-section end "restore-cache"
else
echo "No cache found in ${CACHE_ARCHIVE}"
fi
script:
- cargo -V
- cargo build --profile "${CARGO_PROFILE}" --features "${CARGO_FEATURES}" --all
- cargo test --profile "${CARGO_PROFILE}" --no-default-features -p tarantool
- cargo test --profile "${CARGO_PROFILE}" --features "${CARGO_FEATURES}"
- |
# Save cache
if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
ci-log-section start "save-cache" Saving cache to ${CACHE_ARCHIVE} ...
du -sh ${CACHE_PATHS} || true
TMPEXT=$RANDOM
tar -cf "${CACHE_ARCHIVE}.${TMPEXT}" ${CACHE_PATHS}
mv -f "${CACHE_ARCHIVE}.${TMPEXT}" "${CACHE_ARCHIVE}"
echo Ok
du -sh ${CACHE_ARCHIVE}
ci-log-section end "save-cache"
else
echo "Skip saving cache on a non-master branch"
fi
lint-vanilla:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/vanilla-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_VANILLA}
CARGO_FEATURES: default
script:
- cargo fmt --all --check
- cargo clippy --version
- cargo clippy --features "${CARGO_FEATURES}" --workspace --tests -- --deny warnings
test-vanilla-debug:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/vanilla-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_VANILLA}
CARGO_FEATURES: default
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: debug
CARGO_PROFILE: dev
test-vanilla-release:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/vanilla-release-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_VANILLA}
CARGO_FEATURES: default
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: release
CARGO_PROFILE: release
bench-vanilla:
extends: .test
variables:
BASE_IMAGE_NAME: ${BASE_IMAGE_VANILLA}
script:
- cat /proc/cpuinfo
- make bench
lint-fork:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/picodata-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
CARGO_FEATURES: picodata,tokio_components
script:
- cargo clippy --version
- cargo clippy --features "${CARGO_FEATURES}" --workspace --tests -- --deny warnings
test-fork-debug:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/picodata-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
CARGO_FEATURES: picodata,tokio_components
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: debug
CARGO_PROFILE: dev
test-fork-debug-standalone-decimal:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/picodata-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
CARGO_FEATURES: picodata,tokio_components,standalone_decimal
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: debug
CARGO_PROFILE: dev
test-fork-release:
extends: .test
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/picodata-release-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
CARGO_FEATURES: picodata,tokio_components
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: release
CARGO_PROFILE: release
test-fork-debug-on-trigger:
extends: .test
rules: # overrides whole section from .test
- <<: *if-triggered
variables:
CACHE_ARCHIVE: /shared-storage/tarantool-module/picodata-cache.tar
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
BASE_IMAGE_TAG: ${CI_COMMIT_SHA}-triggered
CARGO_FEATURES: picodata,tokio_components
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: debug
CARGO_PROFILE: dev
test-macos-debug-fork:
extends: .test
tags:
- mac-dev-m1
image:
variables:
CACHE_ARCHIVE: /Users/gitlab_runner/shared-storage/tarantool-module/macos-debug-fork-cache.tar
CARGO_FEATURES: default
CARGO_HOME: /Users/gitlab_runner/.cargo
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: debug
CARGO_PROFILE: dev
script:
- |
touch "${CARGO_HOME}/config.toml" &&
if ! grep "dynamic_lookup" "${CARGO_HOME}/config.toml" &>/dev/null; then
echo '[build]' >> "${CARGO_HOME}/config.toml"
echo 'rustflags = ["-Clink-args=-undefined dynamic_lookup"]' >> "${CARGO_HOME}/config.toml"
fi
- cat "${CARGO_HOME}/config.toml"
- cargo -V
- cargo build --profile "${CARGO_PROFILE}" --features "${CARGO_FEATURES}" --all
- cargo test --profile "${CARGO_PROFILE}" --no-default-features -p tarantool
# On MacOS we must run tests for each package sepparately, because for
# some reason the test executables generated by cargo still contain
# references to the undefined dynamic symbols even though they're actually
# unreachable. There's no such problem on Linux.
- cargo test --profile "${CARGO_PROFILE}" --features "net_box network_client picodata tokio_components" -p tarantool
- cargo test --profile "${CARGO_PROFILE}" -p tlua
- cargo test --profile "${CARGO_PROFILE}" --features "picodata tokio_components" -p tarantool-module-test-runner
- |
# This is one hacky way to reuse a tarantool built on a another pipeline...
find /Users/gitlab_runner/builds -path '*/picodata/tarantool/src/tarantool' -perm +111 -type f | {
tarantool=$(head -1)
if [ -n "${tarantool}" ]; then
set -e
echo "Found a tarantool executable in '${tarantool}'"
${tarantool} --version
${tarantool} ./tests/run_tests.lua
fi
}
- |
# Save cache
if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
ci-log-section start "save-cache" Saving cache to ${CACHE_ARCHIVE} ...
du -sh ${CACHE_PATHS} || true
TMPEXT=$RANDOM
tar -cf "${CACHE_ARCHIVE}.${TMPEXT}" ${CACHE_PATHS}
mv -f "${CACHE_ARCHIVE}.${TMPEXT}" "${CACHE_ARCHIVE}"
echo Ok
du -sh ${CACHE_ARCHIVE}
ci-log-section end "save-cache"
else
echo "Skip saving cache on a non-master branch"
fi
test-macos-release-fork:
extends: test-macos-debug-fork
variables:
CACHE_ARCHIVE: /Users/gitlab_runner/shared-storage/tarantool-module/macos-release-fork-cache.tar
CARGO_FEATURES: default
CARGO_HOME: /Users/gitlab_runner/.cargo
# This variable tells tests/run_tests.lua which version of the library to use for testing
TARANTOOL_MODULE_BUILD_MODE: release
CARGO_PROFILE: release
pages:
extends: .test
variables:
BASE_IMAGE_NAME: ${BASE_IMAGE_FORK}
RUSTDOCFLAGS: "-Dwarnings"
script:
- cargo doc --workspace --no-deps --features "picodata,tokio_components"
- rm -rf public
- mv target/doc public
artifacts:
paths:
- public