-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
190 lines (160 loc) · 7.08 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
# source: https://gitlab.com/testing-farm/artemis/tree/master/container/Dockerfile.gitlab-ci
image: quay.io/testing-farm/gitlab-ci-artemis
stages:
- test_stage
- deploy
variables:
IMAGE: quay.io/testing-farm/artemis
workflow:
rules:
# for merge requests
- if: $CI_MERGE_REQUEST_ID
# for the tip of the default branch
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# for tagged commits
- if: $CI_COMMIT_TAG
tests:
stage: test_stage
variables:
TERM: "xterm"
POETRY_ADDOPTS: "--ansi"
MYPY_FORCE_COLOR: "1"
PYTEST_ADDOPTS: "--color=yes"
PRE_COMMIT_COLOR: "always"
script:
- make -C server/ test-pre-commit
- make -C server/ test-units
- make -C server/ test-db-schema-revisions
- make -C cli/ test-pre-commit
- make -C cli/ test-units
container:
stage: deploy
image: quay.io/buildah/stable:v1.29.0
variables:
IMAGE_REF: $IMAGE:$CI_COMMIT_REF_NAME
IMAGE_REF_DEBUG: $IMAGE:$CI_COMMIT_REF_NAME.debug
IMAGE_SHA: $IMAGE:$CI_COMMIT_SHORT_SHA
IMAGE_SHA_DEBUG: $IMAGE:$CI_COMMIT_SHORT_SHA.debug
IMAGE_TAG: $IMAGE:$CI_COMMIT_TAG
IMAGE_TAG_DEBUG: $IMAGE:$CI_COMMIT_TAG.debug
IMAGE_LATEST: $IMAGE:latest
IMAGE_LATEST_DEBUG: $IMAGE:latest.debug
script:
# Setup push secret
- mkdir -p $HOME/.docker
- echo "$DOCKER_AUTH_CONFIG" > $HOME/.docker/config.json
# Build image - and its debugging variant - tagged with ref (usualy a branch)
- echo "Building image from the ref, $IMAGE_REF"
- buildah bud -t "$IMAGE_REF" -f container/Dockerfile .
- buildah push "$IMAGE_REF"
- echo "Building debugging image from the ref, $IMAGE_REF_DEBUG"
- buildah bud -t "$IMAGE_REF_DEBUG" -f container/Dockerfile.debug --from "${IMAGE_REF}" .
- buildah push "$IMAGE_REF_DEBUG"
# Tag it with short SHA
- echo "Tagging the ref image, $IMAGE_REF, as SHA image, $IMAGE_SHA"
- buildah tag "$IMAGE_REF" "$IMAGE_SHA"
- buildah push "$IMAGE_SHA"
- echo "Tagging the ref debugging image, $IMAGE_REF_DEBUG, as SHA debugging image, $IMAGE_SHA_DEBUG"
- buildah tag "$IMAGE_REF_DEBUG" "$IMAGE_SHA_DEBUG"
- buildah push "$IMAGE_SHA_DEBUG"
# For default branch, publish also a `:latest` image
- if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then
echo "Tagging the ref image, $IMAGE_REF, as latest image, $IMAGE_LATEST";
buildah tag "$IMAGE_REF" "$IMAGE_LATEST";
buildah push "$IMAGE_LATEST";
echo "Tagging the ref debugging image, $IMAGE_REF_DEBUG, as latest debugging image, $IMAGE_LATEST_DEBUG";
buildah tag "$IMAGE_REF_DEBUG" "$IMAGE_LATEST_DEBUG";
buildah push "$IMAGE_LATEST_DEBUG";
fi
# When a commit tag is known (in a pipeline running for a tag), push image with the git tag.
- if [ "$CI_COMMIT_TAG" != "" ]; then
echo "Tagging the ref image, $IMAGE_REF, as tag image, $IMAGE_TAG"
buildah tag "$IMAGE_REF" "$IMAGE_TAG";
buildah push "$IMAGE_TAG";
echo "Tagging the ref debugging image, $IMAGE_REF_DEBUG, as tag debugging image, $IMAGE_TAG_DEBUG";
buildah tag "$IMAGE_REF_DEBUG" "$IMAGE_TAG_DEBUG";
buildah push "$IMAGE_TAG_DEBUG";
fi
.docs:
image: quay.io/testing-farm/gitlab-pages-hugo:latest
variables:
# Theme is linked into docs/themes as a git submodule, and Gitlab is smart enough
# to check it out for us, before we let Hugo run.
GIT_SUBMODULE_STRATEGY: recursive
script:
# Now it's time to generate docs.
- cd docs
# Base URL is set by derived jobs. It's either the public one, when we're generating docs from `main` branch,
# or it is a base URL of URL Gitlab uses when letting us browse artifacts job saved.
- hugo --baseURL="$BASE_URL"
# TODO: here we should generate developer docs from sources, for both client and server.
# We'd use Sphinx for that, and we'd need to store the output in - now empty - directories,
# so we could link to these autogenerated bits from the "static" docs.
# Gitlab expects "public" directory to appear in the local directory of the script,
# which means that we need to move our one level up, since we're working in ./docs.
- mv ./public ../
artifacts:
paths:
- public
# The name must be "pages" for Gitlab to spot it, and upload the docs.
pages:
stage: deploy
extends: .docs
only:
- main
variables:
BASE_URL: "https://${CI_PROJECT_NAMESPACE}.gitlab.io/${CI_PROJECT_NAME}"
# This tells Gitlab to create an environment (under https://gitlab.com/testing-farm/artemis/-/environments) where
# this particular job would be available. It is a common "Gitlab pages" environment, nothing special.
environment:
name: production/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
url: https://${CI_PROJECT_NAMESPACE}.gitlab.io/${CI_PROJECT_NAME}
# This job's for uploading built docs for a preview: into their own Gitlab environment. Note the `environment.url`
# value, which is different that the one for `main` branch - it is actually URL Gitlab uses when job saves
# its artifacts, and Gitlab lets us browse them.
pages:preview:
stage: deploy
extends: .docs
except:
- main
variables:
# Note that this URL matches the environment URL below - this lets us easily to get from the environment
# we have in our MR to the actual pages.
BASE_URL: "https://${CI_PROJECT_NAMESPACE}.gitlab.io/-/${CI_PROJECT_NAME}/-/jobs/${CI_JOB_ID}/artifacts/public"
# By default, Hugo generates "nice" URLs: `content/foo.adoc` becomes `/foo/index.html`, and people
# can then link to `/foo` because webservers will take care of providing the "index: of this directory,
# `index.html`. This does not work with previews, though, as Gitlab pages preview won't supply that
# directory index. To workaround this, we therefore enable "ugly" URLs: `content/foo.adoc` becomes
# `/foo.html`, and all links point to `/foo.html` instead of `/foo/`.
#
# Note that this workaround does build site in a slightly different way that the actual public version,
# and although highly unlikely, it *may* affect how the site works - Hugo is smart enough to take care
# of this URL switching, and pages just work, but be aware the preview is not exactly the same as the final
# site in this regard. For example, never link to internal pages directly using their rendered names like
# `/foo.html`.
HUGO_UGLYURLS: "true"
environment:
name: preview/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
url: https://${CI_PROJECT_NAMESPACE}.gitlab.io/-/${CI_PROJECT_NAME}/-/jobs/${CI_JOB_ID}/artifacts/public/index.html
on_stop: pages:preview:stop
# And final step: when our parent MR is merged, this job takes care of removing the Gitlab environment \o/
pages:preview:stop:
stage: deploy
except:
- main
when: manual
allow_failure: true
environment:
name: preview/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}
action: stop
script:
- echo "bye"
publish_cli:
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- "cli/pyproject.toml"
- when: never
script:
- make -C cli/ publish