4 # Figure out name and path to this file. This isn't
5 # portable but we only care for modern GNU make
6 CI_MAKEFILE = $(abspath $(firstword $(MAKEFILE_LIST)))
8 # The directory holding content on the host that we will
9 # expose to the container.
10 CI_SCRATCHDIR = $(shell pwd)/ci-tree
12 # The root directory of the libvirt.git checkout
13 CI_GIT_ROOT = $(shell git rev-parse --show-toplevel)
15 # The directory holding the clone of the git repo that
16 # we will expose to the container
17 CI_HOST_SRCDIR = $(CI_SCRATCHDIR)/src
19 # The directory holding the source inside the
20 # container, i.e. where we want to expose
21 # the $(CI_HOST_SRCDIR) directory from the host
24 # Relative directory to perform the build in. This
25 # defaults to using a separate build dir, but can be
26 # set to empty string for an in-source tree build.
29 # The directory holding the build output inside the
31 CI_CONT_BUILDDIR = $(CI_CONT_SRCDIR)/$(CI_VPATH)
33 # Can be overridden with mingw{32,64}-configure if desired
34 CI_CONFIGURE = $(CI_CONT_SRCDIR)/configure
36 # Default to using all possible CPUs
37 CI_SMP = $(shell getconf _NPROCESSORS_ONLN)
39 # Any extra arguments to pass to make
42 # Any extra arguments to pass to configure
45 # Avoid pulling submodules over the network by locally
47 CI_SUBMODULES = $(shell git submodule | awk '{ print $$2 }')
49 # Location of the container images we're going to pull
50 # Can be useful to overridde to use a locally built
52 CI_IMAGE_PREFIX = quay.io/libvirt/buildenv-
54 # The default tag is ':latest' but if the container
55 # repo above uses different conventions this can override it
56 CI_IMAGE_TAG = :master
58 # We delete the virtual root after completion, set
59 # to 0 if you need to keep it around for debugging
62 # We'll always freshly clone the virtual root each
63 # time in case it was not cleaned up before. Set
64 # to 1 if you want to try restarting a previously
68 # We need the container process to run with current host IDs
69 # so that it can access the passed in build directory
70 CI_UID = $(shell id -u)
71 CI_GID = $(shell id -g)
74 # Container engine we are going to use, can be overridden per make
75 # invocation, if it is not we try podman and then default to docker.
76 ifeq ($(CI_ENGINE),auto)
77 override CI_ENGINE = $(shell podman version >/dev/null 2>&1 && echo podman || echo docker)
80 # IDs you run as do not need to exist in
81 # the container's /etc/passwd & /etc/group files, but
82 # if they do not, then libvirt's 'make check' will fail
85 # We do not directly mount /etc/{passwd,group} as Docker
86 # is liable to mess with SELinux labelling which will
87 # then prevent the host accessing them. And podman cannot
88 # relabel the files due to it running rootless. So
89 # copying them first is safer and error-prone.
91 --volume $(CI_SCRATCHDIR)/group:/etc/group:ro,z \
92 --volume $(CI_SCRATCHDIR)/passwd:/etc/passwd:ro,z \
95 # Docker containers can have very large ulimits
96 # for nofiles - as much as 1048576. This makes
97 # libvirt very slow at exec'ing programs.
98 CI_ULIMIT_FILES = 1024
100 ifeq ($(CI_ENGINE),podman)
101 # Podman cannot reuse host namespace when running non-root containers. Until
102 # support for --keep-uid is added we can just create another mapping that will
103 # do that for us. Beware, that in {uid,git}map=container_id:host_id:range,
104 # the host_id does actually refer to the uid in the first mapping where 0
105 # (root) is mapped to the current user and rest is offset.
107 # In order to set up this mapping, we need to keep all the user IDs to prevent
108 # possible errors as some images might expect UIDs up to 90000 (looking at you
109 # fedora), so we don't want the overflowuid to be used for them. For mapping
110 # all the other users properly ther eneeds to be some math done. Don't worry,
111 # it's just addition and subtraction.
113 # 65536 ought to be enough (tm), but for really rare cases the maximums might
114 # need to be higher, but that only happens when your /etc/sub{u,g}id allow
115 # users to have more IDs. Unless --keep-uid is supported, let's do this in a
116 # way that should work for everyone.
117 CI_MAX_UID = $(shell sed -n "s/^$USER:[^:]\+://p" /etc/subuid)
118 CI_MAX_GID = $(shell sed -n "s/^$USER:[^:]\+://p" /etc/subgid)
119 ifeq ($(CI_MAX_UID),)
122 ifeq ($(CI_MAX_GID),)
125 CI_UID_OTHER = $(shell echo $$(($(CI_UID)+1)))
126 CI_GID_OTHER = $(shell echo $$(($(CI_GID)+1)))
127 CI_UID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_UID)-$(CI_UID))))
128 CI_GID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_GID)-$(CI_GID))))
131 --uidmap 0:1:$(CI_UID) \
132 --uidmap $(CI_UID):0:1 \
133 --uidmap $(CI_UID_OTHER):$(CI_UID_OTHER):$(CI_UID_OTHER_RANGE) \
134 --gidmap 0:1:$(CI_GID) \
135 --gidmap $(CI_GID):0:1 \
136 --gidmap $(CI_GID_OTHER):$(CI_GID_OTHER):$(CI_GID_OTHER_RANGE) \
140 # Args to use when cloning a git repo.
141 # -c stop it complaining about checking out a random hash
142 # -q stop it displaying progress info for local clone
143 # --local ensure we don't actually copy files
145 -c advice.detachedHead=false \
150 # Args to use when running the container
151 # --rm stop inactive containers getting left behind
152 # --user we execute as the same user & group account
153 # as dev so that file ownership matches host
154 # instead of root:root
155 # --volume to pass in the cloned git repo & config
156 # --workdir to set cwd to vpath build location
157 # --ulimit lower files limit for performance reasons
159 # --tty Ensure we have ability to Ctrl-C the build
162 --user $(CI_UID):$(CI_GID) \
167 --volume $(CI_HOST_SRCDIR):$(CI_CONT_SRCDIR):z \
168 --workdir $(CI_CONT_SRCDIR) \
169 --ulimit nofile=$(CI_ULIMIT_FILES):$(CI_ULIMIT_FILES) \
173 @echo -n "Checking if $(CI_ENGINE) is available..." && \
174 $(CI_ENGINE) version 1>/dev/null && echo "yes"
176 ci-prepare-tree: ci-check-engine
177 @test "$(CI_REUSE)" != "1" && rm -rf $(CI_SCRATCHDIR) || :
178 @if ! test -d $(CI_SCRATCHDIR) ; then \
179 mkdir -p $(CI_SCRATCHDIR); \
180 cp /etc/passwd $(CI_SCRATCHDIR); \
181 cp /etc/group $(CI_SCRATCHDIR); \
182 echo "Cloning $(CI_GIT_ROOT) to $(CI_HOST_SRCDIR)"; \
183 git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT) $(CI_HOST_SRCDIR) || exit 1; \
184 for mod in $(CI_SUBMODULES) ; \
186 test -f $(CI_GIT_ROOT)/$$mod/.git || continue ; \
187 echo "Cloning $(CI_GIT_ROOT)/$$mod to $(CI_HOST_SRCDIR)/$$mod"; \
188 git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT)/$$mod $(CI_HOST_SRCDIR)/$$mod || exit 1; \
192 # $CONFIGURE_OPTS is a env that can optionally be set in the container,
193 # populated at build time from the Dockerfile. A typical use case would
194 # be to pass --host/--target args to trigger cross-compilation
196 # This can be augmented by make local args in $(CI_CONFIGURE_ARGS)
198 # gl_public_submodule_commit= to disable gnulib's submodule check
199 # which breaks due to way we clone the submodules
200 ci-build@%: ci-prepare-tree
201 $(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) \
203 mkdir -p $(CI_CONT_BUILDDIR) || exit 1 ; \
204 cd $(CI_CONT_BUILDDIR) ; \
205 NOCONFIGURE=1 $(CI_CONT_SRCDIR)/autogen.sh || exit 1 ; \
206 $(CI_CONFIGURE) $${CONFIGURE_OPTS} $(CI_CONFIGURE_ARGS) ; \
209 test -f config.log && cat config.log ; \
212 find -name test-suite.log -delete ; \
213 export VIR_TEST_DEBUG=1 ; \
214 make -j$(CI_SMP) gl_public_submodule_commit= $(CI_MAKE_ARGS) ; \
215 if test $$? != 0 ; then \
216 LOGS=`find -name test-suite.log` ; \
217 if test "$${LOGS}" != "" ; then \
218 echo "=== LOG FILE(S) START ===" ; \
220 echo "=== LOG FILE(S) END ===" ; \
224 @test "$(CI_CLEAN)" = "1" && rm -rf $(CI_SCRATCHDIR) || :
227 $(MAKE) -f $(CI_MAKEFILE) ci-build@$* CI_MAKE_ARGS="check"
229 ci-shell@%: ci-prepare-tree
230 $(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) /bin/bash
231 @test "$(CI_CLEAN)" = "1" && rm -rf $(CI_SCRATCHDIR) || :
234 @echo "Build libvirt inside containers used for CI"
236 @echo "Available targets:"
238 @echo " ci-build@\$$IMAGE - run a default 'make'"
239 @echo " ci-check@\$$IMAGE - run a 'make check'"
240 @echo " ci-shell@\$$IMAGE - run an interactive shell"
242 @echo "Available x86 container images:"
249 @echo " fedora-rawhide"
252 @echo "Available cross-compiler container images:"
254 @echo " debian-{9,sid}-cross-aarch64"
255 @echo " debian-{9,sid}-cross-armv6l"
256 @echo " debian-{9,sid}-cross-armv7l"
257 @echo " debian-sid-cross-i686"
258 @echo " debian-{9,sid}-cross-mips64el"
259 @echo " debian-{9,sid}-cross-mips"
260 @echo " debian-{9,sid}-cross-mipsel"
261 @echo " debian-{9,sid}-cross-ppc64le"
262 @echo " debian-{9,sid}-cross-s390x"
264 @echo "Available make variables:"
266 @echo " CI_CLEAN=0 - do not delete '$(CI_SCRATCHDIR)' after completion"
267 @echo " CI_REUSE=1 - re-use existing '$(CI_SCRATCHDIR)' content"
268 @echo " CI_ENGINE=auto - container engine to use (podman, docker)"