-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitlab-ci.yml
154 lines (144 loc) · 5.58 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
stages:
- build
- deploy
- cleanup
services:
- name: docker:dind
command: ["--tls=false"]
variables:
CARGO_INCREMENTAL: "0"
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
DOCKER_TLS_CERTDIR: ""
RUSTC_WRAPPER: /usr/bin/sccache
SCCACHE_REGION: us-east-1
SCCACHE_ENDPOINT: rgw.storage.home.quadra-tec.net:7480
SCCACHE_S3_USE_SSL: "off"
SCCACHE_BUCKET: gitlab-sccache
cargo build and cargo test:
stage: build
image: mcronce/rust-pgo:1.76
cache:
- key: rust
paths:
- .cargo
before_script:
- |
if [ -d .cargo ]; then
rm -Rf /usr/local/cargo/registry
time mv -f .cargo/registry /usr/local/cargo/
fi
script:
- cargo build
- cargo clippy --no-deps -- -D warnings
- cargo test
after_script:
- if [ ! -d .cargo ]; then mkdir .cargo; fi
- time mv -f /usr/local/cargo/registry .cargo/
- /usr/bin/sccache -s
Build x86-64 container image:
stage: build
image: docker:20-git
artifacts:
paths:
- images/release.amd64.tar.gz
before_script:
- docker version
- apk add -U bash coreutils
- bash -ec 'find Cargo.toml src -type f | while read file; do revision="$(git rev-list -n 1 HEAD "${file}")"; timestamp="$(git show --pretty=format:%ai --abbrev-commit "${revision}" | head -n1)"; touch -d "${timestamp}" "${file}"; done'
script:
- |
BUILD_ARGS="--build-arg=CARGO_INCREMENTAL --build-arg=RUSTC_WRAPPER --build-arg=SCCACHE_REGION --build-arg=SCCACHE_ENDPOINT --build-arg=SCCACHE_BUCKET --build-arg=AWS_ACCESS_KEY_ID --build-arg=AWS_SECRET_ACCESS_KEY"
docker build $BUILD_ARGS -f Dockerfile.x86-64 --cache-from "mcronce/oci-registry-builder" --target=builder -t "mcronce/oci-registry-builder" .
docker build $BUILD_ARGS -f Dockerfile.x86-64 --cache-from "mcronce/oci-registry-builder" --cache-from "mcronce/oci-registry" -t "mcronce/oci-registry:amd64" .
- mkdir -pv images
- time docker save "mcronce/oci-registry:amd64" | gzip > images/release.amd64.tar.gz
after_script:
- docker rmi -f "mcronce/oci-registry-builder"
- docker rmi -f "mcronce/oci-registry:amd64"
only:
- tags
Build aarch64 container image:
stage: build
image: docker:20-git
artifacts:
paths:
- images/release.arm64v8.tar.gz
before_script:
- docker version
- apk add -U bash coreutils
- bash -ec 'find Cargo.toml src ui -type f | while read file; do revision="$(git rev-list -n 1 HEAD "${file}")"; timestamp="$(git show --pretty=format:%ai --abbrev-commit "${revision}" | head -n1)"; touch -d "${timestamp}" "${file}"; done'
script:
- |
BUILD_ARGS="--build-arg=CARGO_INCREMENTAL --build-arg=RUSTC_WRAPPER --build-arg=SCCACHE_REGION --build-arg=SCCACHE_ENDPOINT --build-arg=SCCACHE_BUCKET --build-arg=AWS_ACCESS_KEY_ID --build-arg=AWS_SECRET_ACCESS_KEY"
docker build $BUILD_ARGS -f Dockerfile.aarch64 --cache-from "mcronce/oci-registry-builder" --target=builder -t "mcronce/oci-registry-builder" .
docker build $BUILD_ARGS -f Dockerfile.aarch64 --cache-from "mcronce/oci-registry-builder" --cache-from "mcronce/oci-registry" -t "mcronce/oci-registry:arm64v8" .
- mkdir -pv images
- time docker save "mcronce/oci-registry:arm64v8" | gzip > images/release.arm64v8.tar.gz
after_script:
- docker rmi -f "mcronce/oci-registry-builder"
- docker rmi -f "mcronce/oci-registry:arm64v8"
only:
- tags
Lint chart:
stage: build
image: alpine/helm:latest
script:
- helm lint ./dist/helm
Push container image:
stage: deploy
image: docker:20-git
before_script:
- docker version
- echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
- zcat images/release.amd64.tar.gz | docker load
- zcat images/release.arm64v8.tar.gz | docker load
script:
- docker push "mcronce/oci-registry:amd64"
- docker push "mcronce/oci-registry:arm64v8"
- docker manifest create "mcronce/oci-registry:latest" --amend "mcronce/oci-registry:amd64" --amend "mcronce/oci-registry:arm64v8"
- docker manifest push "mcronce/oci-registry:latest"
- |
if [ "${CI_COMMIT_TAG}" != '' ]; then
docker tag "mcronce/oci-registry:amd64" "mcronce/oci-registry:${CI_COMMIT_TAG}-amd64"
docker tag "mcronce/oci-registry:arm64v8" "mcronce/oci-registry:${CI_COMMIT_TAG}-arm64v8"
docker push "mcronce/oci-registry:${CI_COMMIT_TAG}-amd64"
docker push "mcronce/oci-registry:${CI_COMMIT_TAG}-arm64v8"
docker manifest create "mcronce/oci-registry:${CI_COMMIT_TAG}" --amend "mcronce/oci-registry:${CI_COMMIT_TAG}-amd64" --amend "mcronce/oci-registry:${CI_COMMIT_TAG}-arm64v8"
docker manifest push "mcronce/oci-registry:${CI_COMMIT_TAG}"
fi
after_script:
- docker rmi -f "mcronce/oci-registry:amd64"
- docker rmi -f "mcronce/oci-registry:arm64v8"
- docker manifest rm "mcronce/oci-registry:latest"
- |
if [ "${CI_COMMIT_TAG}" != '' ]; then
docker rmi -f "mcronce/oci-registry:${CI_COMMIT_TAG}-amd64"
docker rmi -f "mcronce/oci-registry:${CI_COMMIT_TAG}-arm64v8"
docker manifest rm "mcronce/oci-registry:${CI_COMMIT_TAG}"
fi
only:
- tags
Push chart:
stage: deploy
image: alpine/helm:latest
before_script:
- apk add -U git
- helm plugin install https://github.com/chartmuseum/helm-push.git
script:
- helm cm-push ./dist/helm https://charts.cronce.io
only:
- tags
cargo cache cleanup:
stage: cleanup
image: mcronce/cargo-cache
variables:
RUSTC_WRAPPER: ""
cache:
- key: rust
paths:
- .cargo
before_script: []
script:
- CARGO_HOME=.cargo cargo cache clean-unref
after_script: []