-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
220 lines (200 loc) · 5.21 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
stages:
- lint
- build
- push
- release
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_REF_PROTECTED == "true"
variables:
DOCKERIO_MIRROR: hub.wuhoo.xyz
CARGO_HOME: ${CI_PROJECT_DIR}/.cargo
.cache:
cache:
untracked: false
paths:
- .cargo/.crates.toml
- .cargo/.crates2.json
- .cargo/bin/
- .cargo/registry/index/
- .cargo/registry/cache/
- target/
.lint:
extends: .cache
stage: lint
image: docker.io/library/rust:1.83.0
before_script:
- cargo version
- rustup component add clippy
- rustup component add rustfmt
.non-release:
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
.release:
artifacts:
expire_in: never
rules:
- if: $CI_COMMIT_TAG
when: on_success
lint:clippy:
extends:
- .lint
cache:
key: clippy
script:
- cargo clippy -- -D warnings
lint:format:
extends:
- .lint
cache:
key: format
script:
- cargo fmt -- --check
.build_binary:
extends: .cache
stage: build
image: docker.io/library/rust:1.83.0
needs: &build_needs
- lint:clippy
- lint:format
before_script:
- cargo version
artifacts:
untracked: false
expire_in: 7 days
.build_binary:gnu:
extends: .build_binary
script:
- cargo install --locked --target x86_64-unknown-linux-gnu --path .
- mv -v ${CARGO_HOME}/bin/${CI_PROJECT_NAME} ${CI_PROJECT_NAME}_x86_64-unknown-linux-gnu
cache:
key: gnu
artifacts:
paths:
- ${CI_PROJECT_NAME}_x86_64-unknown-linux-gnu
.build_binary:musl:
extends: .build_binary
script:
- rustup target add x86_64-unknown-linux-musl
- apt update
- apt install -y musl-tools musl-dev
- cargo install --locked --target x86_64-unknown-linux-musl --path .
- mv -v ${CARGO_HOME}/bin/${CI_PROJECT_NAME} ${CI_PROJECT_NAME}_x86_64-unknown-linux-musl
cache:
key: musl
artifacts:
paths:
- ${CI_PROJECT_NAME}_x86_64-unknown-linux-musl
build:container:
stage: build
image:
name: quay.io/buildah/stable:v1.38.0
variables:
STORAGE_DRIVER: vfs
BUILDAH_FORMAT: docker
BUILDAH_ISOLATION: chroot
CGO_ENABLED: 0
needs: *build_needs
before_script:
- echo "${CI_REGISTRY_PASSWORD}" | buildah login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
script:
- >-
buildah build
--layers
--cache-to "${CI_REGISTRY_IMAGE}/build-cache"
--cache-from "${CI_REGISTRY_IMAGE}/build-cache"
--cache-ttl 168h0m0s
--tag ${CI_PROJECT_NAME}
--file Dockerfile
--build-arg "ICONS=${ICONS}"
.
- buildah push localhost/${CI_PROJECT_NAME} docker-archive:image-${ICONS}.tar
artifacts:
untracked: false
expire_in: 1 day
paths:
- image-${ICONS}.tar
when: on_success
parallel:
matrix:
- ICONS:
- no-icons
- dashboard-icons
build:binary:gnu:
extends:
- .build_binary:gnu
- .non-release
build:binary:musl:
extends:
- .build_binary:musl
- .non-release
build:binary:gnu:release:
extends:
- .build_binary:gnu
- .release
build:binary:musl:release:
extends:
- .build_binary:musl
- .release
.push:
stage: push
image:
name: gcr.io/go-containerregistry/crane/debug:v0.15.2
entrypoint: [""]
before_script:
- export IMAGE_ARTIFACT="$([ -z $ICONS ] && echo "image-no-icons.tar" || echo "image-dashboard-icons.tar")"
- echo -e "Using $IMAGE_ARTIFACT"
needs:
- job: build:container
parallel:
matrix:
- ICONS:
- no-icons
- dashboard-icons
parallel:
matrix:
- ICONS:
- "" # Equivalent to no-icons
- -dashboard-icons
push:
extends: .push
script:
- crane auth login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- crane push $IMAGE_ARTIFACT ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}${ICONS}
- crane push $IMAGE_ARTIFACT ${CI_REGISTRY_IMAGE}:latest${ICONS}
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
push:release:
extends:
- .push
- .release
script:
- crane auth login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- crane push $IMAGE_ARTIFACT ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}${ICONS}
- crane push $IMAGE_ARTIFACT ${CI_REGISTRY_IMAGE}:stable${ICONS}
release:
extends: .release
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:v0.20.0
needs:
- build:binary:gnu:release
- build:binary:musl:release
- push:release
script:
- echo "Creating release for $CI_COMMIT_TAG"
release:
name: "Release $CI_COMMIT_TAG"
description: './release-notes/$CI_COMMIT_TAG/CHANGELOG.md'
tag_name: "$CI_COMMIT_TAG"
ref: "$CI_COMMIT_TAG"
assets:
links:
- name: '${CI_PROJECT_NAME}_x86_64-unknown-linux-gnu'
url: '$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/${CI_PROJECT_NAME}_x86_64-unknown-linux-gnu?job=build:binary:gnu:release'
- name: '${CI_PROJECT_NAME}_x86_64-unknown-linux-musl'
url: '$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/${CI_PROJECT_NAME}_x86_64-unknown-linux-musl?job=build:binary:musl:release'