server/crypto.c: Improve error messages in crypto_send
[nbdkit.git] / ci / README.rst
blobe9280daf906d586ac1c19bc358ba3926fd683a65
1 Continuous Integration
2 ======================
4 This document provides describes the continuous integration setup for this
5 repository.
7 The main script that is executed is ``ci/build.sh`` and should contain all
8 necessary checks to be performed, although some of them might be run
9 conditionally.
11 lcitool
12 -------
14 GitLab CI does not provide large variety of platforms to run the builds on, but
15 there are couple of remedies for that. The setup used here leverages command
16 called ``lcitool`` which is provided by `libvirt-ci`_
18 The ``lcitool`` simplifies various repeating work that would otherwise need to
19 be repeated quite often and also abstracts away lot of platform specific details
20 like package installation etc.
22 For that to work properly the list of dependencies is part of libvirt-ci and it
23 also provides mapping for different naming conventions used by various
24 distributions.
26 In order to run ``lcitool`` it is enough to have the repository cloned locally,
27 the executable script is in the root directory of that repository.
29 Linux builds
30 ------------
32 In order to run builds on various Linux distributions the CI uses containers to
33 widen the coverage, so the tests are run with GitLab CI's docker setup.
34 Container images are prepared during the build and cached, so that they do not
35 need to be rebuilt for every run, or even built from scratch when changed
36 slightly. The cached container images can be deleted at any time as they will
37 be correctly rebuilt in case of a cache miss. The Dockerfiles are generated
38 using ``lcitool`` and stored under ``ci/containers``. In order to update the
39 files one needs to run ``lcitool manifest ci/manifest.yml`` from the root of the
40 git repository, for example after an update to libvirt-ci (e.g. when adding a
41 new dependency).
43 Recreating the builds locally is pretty straightforward. Choose a file from
44 ``ci/containers`` which represents the desired setup. In this example let's
45 pick Fedora rawhide.
47 In order to build your container image and tag it (optional, but easier to refer
48 to later on) we can utilise podman (or feel free to substitute "podman" with
49 "docker"):
51 .. code-block:: shell
53     podman build -f ci/containers/fedora-rawhide.Dockerfile -t nbdkit-fedora-rawhide
55 That will get you a container image tagged ``nbdkit-fedora-rawhide`` that you
56 can execute the tests on. You can then start a container using the image, in
57 this case from the root of the repository:
59 .. code-block:: shell
61     podman run -it --rm --userns=keep-id -v .:/repo:z -w /repo nbdkit-fedora-rawhide bash
65 .. code-block:: shell
67     docker run -it --rm --user $UID:$UID -v $PWD:/repo:z -w /repo nbdkit-fedora-rawhide bash
69 which will bind-mount the current directory (root of the repository in our case)
70 onto /repo inside the container and also use that path as the working directory
71 (just so you do not have to ``cd /repo`` before any commands. This example
72 illustrates running bash, which can be used to debug any issues in the build,
73 but any command can be specified, for example the build script directly.  It
74 also runs the command under a user with the same UID as the user running the
75 command (even with the same UID).
77 Since the directory is bind-mounted any changes will be visible in your local
78 repository and vice versa. That is useful when you want to, for example, make a
79 change using your favourite editor, but already have some changes in the running
80 container.
82 To avoid common issues and replicate a clean build inside the container you
83 should clean everything or at least use a VPATH build.
85 FreeBSD and macOS
86 -----------------
88 GitLab CI does not offer shared runners for any of these platforms. To work
89 around this limitation, we take advantage of `Cirrus CI`_'s free offering: more
90 specifically, we use the `cirrus-run`_ script to trigger Cirrus CI jobs from
91 GitLab CI jobs so that the workaround is almost entirely transparent to users
92 and there's no need to constantly check two separate CI dashboards.
94 Reproducing these builds locally is not as straightforward as with the
95 containers. For FreeBSD you need to set up your own VM and there is no way to
96 run the macOS builds without the hardware.
98 You can, however have the CI running the build for your GitLab fork, although
99 there is a one-time setup required. If you want FreeBSD and macOS builds to
100 happen when you push to your GitLab repository, you need to
102 * set up a GitHub repository for the project, eg. ``yourusername/reponame``.
103   This repository needs to exist for cirrus-run to work, but it doesn't need to
104   be kept up to date, so you can create it and then forget about it;
106 * enable the `Cirrus CI GitHub app`_ for your GitHub account;
108 * sign up for Cirrus CI. It's enough to log into the website using your GitHub
109   account;
111 * grab an API token from the `Cirrus CI settings`_ page;
113 * it may be necessary to push an empty ``.cirrus.yml`` file to your github fork
114   for Cirrus CI to properly recognize the project. You can check whether
115   Cirrus CI knows about your project by navigating to:
117   ``https://cirrus-ci.com/yourusername/reponame``
119 * in the *CI/CD / Variables* section of the settings page for your GitLab
120   repository, create two new variables:
122   * ``CIRRUS_GITHUB_REPO``, containing the name of the GitHub repository
123     created earlier, eg. ``yourusername/reponame``;
125   * ``CIRRUS_API_TOKEN``, containing the Cirrus CI API token generated earlier.
126     This variable **must** be marked as *Masked*, because anyone with knowledge
127     of it can impersonate you as far as Cirrus CI is concerned.
129   Neither of these variables should be marked as *Protected*, because in
130   general you'll want to be able to trigger Cirrus CI builds from non-protected
131   branches.
133 Once this one-time setup is complete, you can just keep pushing to your GitLab
134 repository as usual and you'll automatically get the additional CI coverage.
136 .. _libvirt-ci: https://gitlab.com/libvirt/libvirt-ci`_.
137 .. _Cirrus CI GitHub app: https://github.com/marketplace/cirrus-ci
138 .. _Cirrus CI settings: https://cirrus-ci.com/settings/profile/
139 .. _Cirrus CI: https://cirrus-ci.com/
140 .. _MinGW: http://mingw.org/
141 .. _cirrus-run: https://github.com/sio/cirrus-run/