-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
256 lines (231 loc) · 7.87 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
256 lines (231 loc) · 7.87 KB
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
variables:
# Set Gitlab's cache compression to tar+zstd for better performance.
CACHE_COMPRESSION_FORMAT: tarzstd
# Enable timestamps in Gitlab's job logs.
FF_TIMESTAMPS: true
# We use submodules
GIT_SUBMODULE_STRATEGY: recursive
# Force cargo colors
CARGO_TERM_COLOR: always
# See https://docs.gitlab.com/ci/yaml/workflow/#git-flow-with-merge-request-pipelines
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
.default-before-script:
before_script:
- pacman-key --init
- pacman -Syu --needed --noconfirm just mkcert
.with-rust:
before_script:
- !reference [".default-before-script", "before_script"]
# pkgconf: for the openssl crate to locate libssl files
- pacman -Syu --needed --noconfirm rust just gcc pkgconf
variables:
RUST_LOG: debug
cache:
key: ${CI_COMMIT_REF_SLUG}-${CI_JOB_NAME}
paths:
- .cargo/bin
- .cargo/registry/index
- .cargo/registry/cache
- target/debug/deps
- target/debug/build
- target/release/deps
- target/release/build
variables:
CARGO_HOME: ${CI_PROJECT_DIR}/.cargo
stages:
- check-and-build
- push
- deploy
licenses:
stage: check-and-build
extends: .default-before-script
script:
- pacman -Syu --needed --noconfirm reuse
- just licenses
check-dependencies:
stage: check-and-build
extends: .with-rust
script:
- pacman -Syu --needed --noconfirm cargo-deny
- just check-dependencies
lint:
stage: check-and-build
extends: .with-rust
script:
- just lint
er-diagram:
stage: check-and-build
extends: .with-rust
variables:
BUILDBTW_DATABASE_FILE: buildbtw_backend.sqlite
script:
- cargo install 'sea-orm-cli@^2.0.0-rc' --force
- just migrate-database
- PATH="$PATH:$CARGO_HOME/bin" just er-diagram
artifacts:
expose_as: "ER Diagram"
paths:
- target/sea-orm-cli-generated/entities.html
- target/sea-orm-cli-generated/entities.mermaid
test:
tags:
stage: check-and-build
extends: .with-rust
script:
- pacman -Syu --needed --noconfirm cargo-nextest
- just test
test-e2e:
tags:
# the test suite needs to spawn podman containers, so we run this job in a VM
- vm
stage: check-and-build
extends: .with-rust
script:
- pacman -Syu --needed --noconfirm cargo-nextest podman geckodriver firefox
- just install-dev-ca
- just gen-dev-cert
- just test-e2e
.build-release:
stage: check-and-build
extends: .with-rust
artifacts:
paths:
- target/release/buildbtw-backend
- target/release/buildbtw-executor
script:
- just build-release
build-release:
extends: .build-release
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
build-release:secure:
extends: .build-release
tags:
- secure
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Don't run this in forks - they don't have access to secure runners
- if: $CI_PROJECT_PATH != "archlinux/buildbtw"
when: never
.push-container-image:
stage: push
extends: .default-before-script
script:
- pacman -Syu --needed --noconfirm podman
- just build-release-container-image
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
# This branch is for main branch builds.
# REGISTRY_USERNAME/REGISTRY_PASSWORD are injected as CI/CD vars.
# They represent a deploy token that has registry write access so we can overwrite protected tags.
# The automatic $CI_REGISTRY_USER/$CI_REGISTRY_PASSWORD can't overwrite protected tags.
#
# If this is a build on main, additionally add a staging tag
podman login -u "$REGISTRY_USERNAME" -p "$REGISTRY_PASSWORD" "$CI_REGISTRY"
podman push buildbtw-backend "$CI_REGISTRY_IMAGE/backend:$CI_COMMIT_REF_SLUG"
podman push buildbtw-backend "$CI_REGISTRY_IMAGE/backend:staging"
podman artifact add "$CI_REGISTRY_IMAGE/executor:$CI_COMMIT_REF_SLUG" target/release/buildbtw-executor
podman artifact push "$CI_REGISTRY_IMAGE/executor:$CI_COMMIT_REF_SLUG"
podman artifact add "$CI_REGISTRY_IMAGE/executor:staging" target/release/buildbtw-executor
podman artifact push "$CI_REGISTRY_IMAGE/executor:staging"
elif [[ "$CI_COMMIT_TAG" == v* ]]; then
# This branch is for tagged builds (aka releases).
# REGISTRY_USERNAME/REGISTRY_PASSWORD are injected as CI/CD vars.
# They represent a deploy token that has registry write access so we can overwrite protected tags.
# The automatic $CI_REGISTRY_USER/$CI_REGISTRY_PASSWORD can't overwrite protected tags.
#
# If this is building a version tag, additionally add a release tag
podman login -u "$REGISTRY_USERNAME" -p "$REGISTRY_PASSWORD" "$CI_REGISTRY"
podman push buildbtw-backend "$CI_REGISTRY_IMAGE/backend:$CI_COMMIT_TAG"
podman push buildbtw-backend "$CI_REGISTRY_IMAGE/backend:release"
podman artifact add "$CI_REGISTRY_IMAGE/executor:$CI_COMMIT_TAG" target/release/buildbtw-executor
podman artifact push "$CI_REGISTRY_IMAGE/executor:$CI_COMMIT_TAG"
podman artifact add "$CI_REGISTRY_IMAGE/executor:release" target/release/buildbtw-executor
podman artifact push "$CI_REGISTRY_IMAGE/executor:release"
else
# This branch is for merge request builds.
podman login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
podman push buildbtw-backend "$CI_REGISTRY_IMAGE/backend:$CI_COMMIT_REF_SLUG"
fi
push-container-image:
extends: .push-container-image
needs: ["build-release"]
tags:
# We build containers so it's easier to do this in a VM
- vm
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
# Don't run this in forks - there's no point to pushing container images in forks
- if: $CI_PROJECT_PATH != "archlinux/buildbtw"
when: never
push-container-image:secure:
extends: .push-container-image
needs: ["build-release:secure"]
tags:
# We build containers so it's easier to do this in a VM
- vm
- secure
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Don't run this in forks - they don't have access to secure runners
- if: $CI_PROJECT_PATH != "archlinux/buildbtw"
when: never
deploy-review-app:
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- >-
curl
--no-progress-meter
--location
--fail-with-body
--header "Authorization: Bearer $BUILDBTW_DEV_DEPLOY_TOKEN"
https://buildbtw.archlinux.review/hooks/deploy-branch?image-tag=$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
auto_stop_in: 2 weeks
url: https://$CI_COMMIT_REF_SLUG.buildbtw.archlinux.review
on_stop: stop-review-app
stop-review-app:
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- >-
curl
--no-progress-meter
--location
--fail-with-body
--header "Authorization: Bearer $BUILDBTW_DEV_DEPLOY_TOKEN"
https://buildbtw.archlinux.review/hooks/undeploy-branch?image-tag=$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
when: manual
deploy-staging:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Don't run this in forks - they don't have access to secure runners
- if: $CI_PROJECT_PATH != "archlinux/buildbtw"
when: never
tags:
- secure
script:
- >-
curl
--no-progress-meter
--location
--fail-with-body
--header "Authorization: Bearer $BUILDBTW_STAGING_DEPLOY_TOKEN"
https://buildbtw.archlinux.builders/hooks/deploy-branch?image-tag=staging
environment:
name: staging
url: https://buildbtw.archlinux.builders