| 1 |
This directory contains the YAML pipeline(s) and a bunch of ancillary scripts |
| 2 |
for our gitlab.com CI. |
| 3 |
|
| 4 |
Running CI locally |
| 5 |
------------------ |
| 6 |
|
| 7 |
Because the gitlab.com jobs run in Docker containers, you can get a pretty |
| 8 |
close match to the CI environment locally, which is useful for debugging. |
| 9 |
These steps mount your Charliecloud source directory live inside the |
| 10 |
container, so you can actually iterate on the code. |
| 11 |
|
| 12 |
WARNING: CHARLIECLOUD DEVELOPERS SHOULD NOT USE THIS AS A SUBSTITUTE FOR A |
| 13 |
HOST ENVIRONMENT THAT PASSES TESTS. |
| 14 |
|
| 15 |
To run the test suite interactively in such an environment: |
| 16 |
|
| 17 |
1. Build the Docker image you need, with ./build-images or manually. |
| 18 |
|
| 19 |
2. Get a shell with e.g.: |
| 20 |
|
| 21 |
$ docker run --privileged -it -w /src \ |
| 22 |
--mount type=bind,src=.,dst=/src ci_debian |
| 23 |
|
| 24 |
NOTE: This assumes that the “docker” command can deal with your web |
| 25 |
proxy, if any. See the FAQ. |
| 26 |
|
| 27 |
WARNING re. Git worktrees: The error “fatal: not a git repository” does |
| 28 |
not immediately stop the build but will break the tests. In Git |
| 29 |
worktrees, .git is not the repository contents but rather a plain file |
| 30 |
containing the host absolute path of the repository. Because we only |
| 31 |
bind-mounted “.”, this directory is not available in the container. There |
| 32 |
are workarounds but I haven’t figured out a good one. |
| 33 |
|
| 34 |
3. Run something pretty close the “test” job: |
| 35 |
|
| 36 |
> cd /builds/charliecloud/charliecloud |
| 37 |
> test/gitlab.com/testjob.sh |
| 38 |
|
| 39 |
4. Or, because you have an interactive shell, you can test whatever. The |
| 40 |
script above (and the one it calls) has steps to consider. The container |
| 41 |
path contains “/builds/charliecloud/main/bin” for your convenience. |
| 42 |
|
| 43 |
According to the internet, you can also run the actual GitLab runner in a |
| 44 |
local Docker container [8]. I have not tested this. |
| 45 |
|
| 46 |
|
| 47 |
Misc useful things to know |
| 48 |
--------------------------- |
| 49 |
|
| 50 |
* Each “job” gets its own ephemeral VM [1], which is different from GitHub |
| 51 |
Actions. You can pass things between jobs with: |
| 52 |
|
| 53 |
1. “artifacts”, which are basically zip files that the runners pass around |
| 54 |
and zip/unzip automatically [2], or |
| 55 |
|
| 56 |
2. the “cache”, which is also a zip file but manipulated using different |
| 57 |
rules that seem a bit tricky to me [3]. The cache limit is 5 GiB. |
| 58 |
|
| 59 |
Each job creates at most one artifact. |
| 60 |
|
| 61 |
Notes/gotchas: |
| 62 |
|
| 63 |
1. The Git working directory ($CI_PROJECT_DIR) is *not* automatically |
| 64 |
transferred between jobs. Use the “artifacts:untracked” keyword. |
| 65 |
|
| 66 |
2. Only files below the Git working directory may be put in the artifact. |
| 67 |
|
| 68 |
3. Artifacts kind of don’t work with “parallel:matrix”. See below. |
| 69 |
|
| 70 |
* A “pipeline” is a DAG of jobs. A project has one pipeline unless you use |
| 71 |
“downstream pipelines” [11], which seemed overly complicated to me. |
| 72 |
Therefore we only have one pipeline.yaml, but we have a MODE variable that |
| 73 |
gates some of the jobs. |
| 74 |
|
| 75 |
* The “workflow” keyword controls whether the pipeline is created at all, |
| 76 |
while “rules” keywords within each job control whether that job is added to |
| 77 |
the pipeline. |
| 78 |
|
| 79 |
* Pushing to a branch associated with a MR causes two pipelines: |
| 80 |
|
| 81 |
1. A “branch pipeline” for the tip of the branch, labeled “branch” in the |
| 82 |
web UI. |
| 83 |
|
| 84 |
2. A “merge request pipeline” for the result of merging the branch to the |
| 85 |
target branch (usually main), labeled “branch”. |
| 86 |
|
| 87 |
We want the second because this will catch bugs introduced by the new code |
| 88 |
as well as the merge itself. Therefore we exclude the first in the |
| 89 |
“workflow” keyword. |
| 90 |
|
| 91 |
Notes/gotchas: |
| 92 |
|
| 93 |
1. If the branch doesn’t merge automatically, there is no pipeline at all. |
| 94 |
|
| 95 |
2. We have no access to the actual commit message, only a fake one |
| 96 |
generated by GitLab for the merge commit. |
| 97 |
|
| 98 |
* Within the ephemeral VM, each job *also* runs inside a Docker container |
| 99 |
using an image you select. Notably, this is “--privileged” Docker, so |
| 100 |
“Docker-In-Docker” (DIND) works, as does Charliecloud [4]. |
| 101 |
|
| 102 |
In our pipeline, we first build some container images suitable for building |
| 103 |
and running Charliecloud (if they need updating), then use those for the |
| 104 |
rest of the pipeline. |
| 105 |
|
| 106 |
Dockerfile notes/gotchas: |
| 107 |
|
| 108 |
* These Dockerfiles must use HTTP(S) transport, not SSH, because CI (and |
| 109 |
also maybe Docker) will not have your SSH keys, which are needed for |
| 110 |
pulling even public repositories. |
| 111 |
|
| 112 |
* Unless otherwise specified, we use the most recent tagged version of |
| 113 |
dependencies. |
| 114 |
|
| 115 |
* When iterating, run build-images locally to take advantage of your |
| 116 |
Docker cache (the CI workers start fresh every time). |
| 117 |
|
| 118 |
* Writing shell scripts within YAML is tricky, mostly because of nasty |
| 119 |
interactions between shell and YAML quoting [5]. We have various workarounds |
| 120 |
for this. |
| 121 |
|
| 122 |
* Standard output and standard error lines can be out of order (e.g. “set +x” |
| 123 |
traces). |
| 124 |
|
| 125 |
* The GitLab web UI *does* interpret ANSI escape codes. |
| 126 |
|
| 127 |
* While we do define stages, if a job specifies “needs”, then it runs when all |
| 128 |
the needed jobs finish, regardless of stage [10]. Otherwise, it runs when |
| 129 |
all jobs in the prior stage finish. |
| 130 |
|
| 131 |
FIXME — no artifact transfer between corresponding parallel jobs |
| 132 |
- generate the .yml file (via “trigger”?) |
| 133 |
- put Charliecloud build/test in the same job so no artifact needed |
| 134 |
|
| 135 |
|
| 136 |
Matrix |
| 137 |
------ |
| 138 |
|
| 139 |
GitLab runs jobs in parallel using a “matrix”, which a set of variable-value |
| 140 |
vectors specified using Cartesian products or one-off entries (i.e., it’s a |
| 141 |
sparse matrix so we are good citizens with CI resources and don’t clutter the |
| 142 |
results with distracting values). |
| 143 |
|
| 144 |
Notably, matrix jobs cannot pass a single artifact to a later, corresponding |
| 145 |
matrix job [6]. For this reason, we build Charliecloud and run the entire test |
| 146 |
suite in a single job. Some of the jobs exit after building Charliecloud. |
| 147 |
Alternatives include: |
| 148 |
|
| 149 |
1. Generate some/all of the .yml files (via “trigger”?), which would allow |
| 150 |
us to have parallel jobs via generated names rather than matrix. This |
| 151 |
seemed too complicated for the benefit. |
| 152 |
|
| 153 |
2. Download and unpack artifacts via the API (in “script”) rather than YAML |
| 154 |
directives. This also seemed too complicated, especially since we need to |
| 155 |
preserve file metadata. |
| 156 |
|
| 157 |
Notes/gotchas: |
| 158 |
|
| 159 |
1. Values are strings and cannot be duplicates [7]. This leads to some |
| 160 |
contrived values. |
| 161 |
|
| 162 |
2. All-caps variables prefixed by “CH_” are used by Charliecloud, while |
| 163 |
lower-case “ci_” are used by this pipeline. Hence the more descriptive |
| 164 |
values for lower-case. |
| 165 |
|
| 166 |
Matrix dimensions with variable names and possible values: |
| 167 |
|
| 168 |
1. CH_TEST_BUILDER (ch-image, docker) |
| 169 |
|
| 170 |
2. CH_IMAGE_CACHE (enabled, rebuild, disabled) |
| 171 |
|
| 172 |
3. CH_TEST_PACK_FMT (squash-mount, squash-unpack, tar-unpack) |
| 173 |
|
| 174 |
4. ci_arch (amd64, arm64) |
| 175 |
|
| 176 |
Architecture. Values need to match the gitlab.com runner tags [9]. |
| 177 |
|
| 178 |
4. ci_distro (see *.df) |
| 179 |
|
| 180 |
Linux distribution. The main considerations are compiler and libc. |
| 181 |
|
| 182 |
5. ci_sudo (sudo-yes, sudo-no) |
| 183 |
|
| 184 |
Whether the “charlie” user that the tests run as has sudo for the test |
| 185 |
suite. The images set up the user with sudo and then “before_script” |
| 186 |
deletes it if appropriate. |
| 187 |
|
| 188 |
|
| 189 |
References |
| 190 |
---------- |
| 191 |
|
| 192 |
[1]: https://docs.gitlab.com/ee/ci/runners |
| 193 |
[2]: https://docs.gitlab.com/ee/ci/jobs/job_artifacts.html |
| 194 |
[3]: https://docs.gitlab.com/ee/ci/caching |
| 195 |
[4]: https://hub.docker.com/_/docker |
| 196 |
[5]: https://yaml-multiline.info |
| 197 |
[6]: https://forum.gitlab.com/t/how-to-matrix-subsequent-jobs-referencing-artifacts-from-previous-matrix-job/66849/2 |
| 198 |
[7]: https://docs.gitlab.com/ee/ci/yaml/index.html#parallelmatrix |
| 199 |
[8]: https://stackoverflow.com/a/65920577 |
| 200 |
[9]: https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html |
| 201 |
[10]: https://docs.gitlab.com/ee/ci/yaml/needs.html |
| 202 |
[11]: https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html |
| 203 |
[12]: https://docs.gitlab.com/ci/yaml/workflow/#switch-between-branch-pipelines-and-merge-request-pipelines |
| 204 |
|
| 205 |
|
| 206 |
-- |
| 207 |
LocalWords: parallelmatrix FMT ci needsparallelmatrix readonly dst testjob |