4 # The root directory of the libvirt.git checkout
5 CI_GIT_ROOT
= $(shell git rev-parse
--show-toplevel
)
7 # The root directory for all CI-related contents
8 CI_ROOTDIR
= $(CI_GIT_ROOT
)/ci
10 # The directory holding content on the host that we will
11 # expose to the container.
12 CI_SCRATCHDIR
= $(CI_ROOTDIR
)/scratch
14 # The directory holding the clone of the git repo that
15 # we will expose to the container
16 CI_HOST_SRCDIR
= $(CI_SCRATCHDIR
)/src
18 # The directory holding the source inside the
19 # container, i.e. where we want to expose
20 # the $(CI_HOST_SRCDIR) directory from the host
21 CI_CONT_SRCDIR
= $(CI_USER_HOME
)/libvirt
23 # Relative directory to perform the build in. This
24 # defaults to using a separate build dir, but can be
25 # set to empty string for an in-source tree build.
28 # The directory holding the build output inside the
30 CI_CONT_BUILDDIR
= $(CI_CONT_SRCDIR
)/$(CI_VPATH
)
32 # Can be overridden with mingw{32,64}-configure if desired
33 CI_CONFIGURE
= $(CI_CONT_SRCDIR
)/configure
35 # Default to using all possible CPUs
36 CI_SMP
= $(shell getconf _NPROCESSORS_ONLN
)
38 # Any extra arguments to pass to make
41 # Any extra arguments to pass to configure
44 # Script containing environment preparation steps
45 CI_PREPARE_SCRIPT
= $(CI_ROOTDIR
)/prepare.sh
47 # Script containing build instructions
48 CI_BUILD_SCRIPT
= $(CI_ROOTDIR
)/build.sh
50 # Location of the container images we're going to pull
51 # Can be useful to overridde to use a locally built
53 CI_IMAGE_PREFIX
= quay.io
/libvirt
/buildenv-libvirt-
55 # The default tag is ':latest' but if the container
56 # repo above uses different conventions this can override it
57 CI_IMAGE_TAG
= :latest
59 # We delete the virtual root after completion, set
60 # to 0 if you need to keep it around for debugging
63 # We'll always freshly clone the virtual root each
64 # time in case it was not cleaned up before. Set
65 # to 1 if you want to try restarting a previously
69 # We need the container process to run with current host IDs
70 # so that it can access the passed in build directory
71 CI_UID
= $(shell id
-u
)
72 CI_GID
= $(shell id
-g
)
74 # We also need the user's login and home directory to prepare the
75 # environment the way some programs expect it
76 CI_USER_LOGIN
= $(shell echo
"$$USER")
77 CI_USER_HOME
= $(shell echo
"$$HOME")
80 # Container engine we are going to use, can be overridden per make
81 # invocation, if it is not we try podman and then default to docker.
82 ifeq ($(CI_ENGINE
),auto
)
83 override CI_ENGINE
= $(shell podman version
>/dev
/null
2>&1 && echo podman || echo docker
)
86 # IDs you run as do not need to exist in
87 # the container's /etc/passwd & /etc/group files, but
88 # if they do not, then libvirt's 'make check' will fail
91 # We do not directly mount /etc/{passwd,group} as Docker
92 # is liable to mess with SELinux labelling which will
93 # then prevent the host accessing them. And podman cannot
94 # relabel the files due to it running rootless. So
95 # copying them first is safer and less error-prone.
97 --volume
$(CI_SCRATCHDIR
)/group
:/etc
/group
:ro
,z \
98 --volume
$(CI_SCRATCHDIR
)/passwd
:/etc
/passwd
:ro
,z \
102 --volume
$(CI_SCRATCHDIR
)/home
:$(CI_USER_HOME
):z \
106 --volume
$(CI_SCRATCHDIR
)/prepare
:$(CI_USER_HOME
)/prepare
:z \
107 --volume
$(CI_SCRATCHDIR
)/build
:$(CI_USER_HOME
)/build
:z \
110 # Docker containers can have very large ulimits
111 # for nofiles - as much as 1048576. This makes
112 # libvirt very slow at exec'ing programs.
113 CI_ULIMIT_FILES
= 1024
115 ifeq ($(CI_ENGINE
),podman
)
116 # Podman cannot reuse host namespace when running non-root
117 # containers. Until support for --keep-uid is added we can
118 # just create another mapping that will do that for us.
119 # Beware, that in {uid,git}map=container_id:host_id:range, the
120 # host_id does actually refer to the uid in the first mapping
121 # where 0 (root) is mapped to the current user and rest is
124 # In order to set up this mapping, we need to keep all the
125 # user IDs to prevent possible errors as some images might
126 # expect UIDs up to 90000 (looking at you fedora), so we don't
127 # want the overflowuid to be used for them. For mapping all
128 # the other users properly, some math needs to be done.
129 # Don't worry, it's just addition and subtraction.
131 # 65536 ought to be enough (tm), but for really rare cases the
132 # maximums might need to be higher, but that only happens when
133 # your /etc/sub{u,g}id allow users to have more IDs. Unless
134 # --keep-uid is supported, let's do this in a way that should
136 CI_MAX_UID
= $(shell sed
-n
"s/^$(CI_USER_LOGIN):[^:]\+://p" /etc
/subuid
)
137 CI_MAX_GID
= $(shell sed
-n
"s/^$(CI_USER_LOGIN):[^:]\+://p" /etc
/subgid
)
138 ifeq ($(CI_MAX_UID
),)
141 ifeq ($(CI_MAX_GID
),)
144 CI_UID_OTHER
= $(shell echo
$$(($(CI_UID
)+1)))
145 CI_GID_OTHER
= $(shell echo
$$(($(CI_GID
)+1)))
146 CI_UID_OTHER_RANGE
= $(shell echo
$$(($(CI_MAX_UID
)-$(CI_UID
))))
147 CI_GID_OTHER_RANGE
= $(shell echo
$$(($(CI_MAX_GID
)-$(CI_GID
))))
150 --uidmap
0:1:$(CI_UID
) \
151 --uidmap
$(CI_UID
):0:1 \
152 --uidmap
$(CI_UID_OTHER
):$(CI_UID_OTHER
):$(CI_UID_OTHER_RANGE
) \
153 --gidmap
0:1:$(CI_GID
) \
154 --gidmap
$(CI_GID
):0:1 \
155 --gidmap
$(CI_GID_OTHER
):$(CI_GID_OTHER
):$(CI_GID_OTHER_RANGE
) \
159 # Args to use when cloning a git repo.
160 # -c stop it complaining about checking out a random hash
161 # -q stop it displaying progress info for local clone
162 # --local ensure we don't actually copy files
164 -c advice.detachedHead
=false \
169 # Args to use when running the container
170 # --rm stop inactive containers getting left behind
171 # --user we execute as the same user & group account
172 # as dev so that file ownership matches host
173 # instead of root:root
174 # --volume to pass in the cloned git repo & config
175 # --ulimit lower files limit for performance reasons
177 # --tty Ensure we have ability to Ctrl-C the build
185 $(CI_SCRIPT_MOUNTS
) \
186 --volume
$(CI_HOST_SRCDIR
):$(CI_CONT_SRCDIR
):z \
187 --ulimit nofile
=$(CI_ULIMIT_FILES
):$(CI_ULIMIT_FILES
) \
188 --cap-add
=SYS_PTRACE \
192 @echo
-n
"Checking if $(CI_ENGINE) is available..." && \
193 $(CI_ENGINE
) version
1>/dev
/null
&& echo
"yes"
195 ci-prepare-tree
: ci-check-engine
196 @
test "$(CI_REUSE)" != "1" && rm -rf
$(CI_SCRATCHDIR
) ||
:
197 @if
! test -d
$(CI_SCRATCHDIR
) ; then \
198 mkdir
-p
$(CI_SCRATCHDIR
); \
199 cp
/etc
/passwd
$(CI_SCRATCHDIR
); \
200 cp
/etc
/group
$(CI_SCRATCHDIR
); \
201 mkdir
-p
$(CI_SCRATCHDIR
)/home
; \
202 cp
"$(CI_PREPARE_SCRIPT)" $(CI_SCRATCHDIR
)/prepare
; \
203 cp
"$(CI_BUILD_SCRIPT)" $(CI_SCRATCHDIR
)/build
; \
204 chmod
+x
"$(CI_SCRATCHDIR)/prepare" "$(CI_SCRATCHDIR)/build"; \
205 echo
"Cloning $(CI_GIT_ROOT) to $(CI_HOST_SRCDIR)"; \
206 git clone
$(CI_GIT_ARGS
) $(CI_GIT_ROOT
) $(CI_HOST_SRCDIR
) || exit
1; \
207 for mod in
$$(git submodule | awk
'{ print $$2 }' | sed
-E
's,^../,,g') ; \
209 test -f
$(CI_GIT_ROOT
)/$$mod/.git || continue
; \
210 echo
"Cloning $(CI_GIT_ROOT)/$$mod to $(CI_HOST_SRCDIR)/$$mod"; \
211 git clone
$(CI_GIT_ARGS
) $(CI_GIT_ROOT
)/$$mod $(CI_HOST_SRCDIR
)/$$mod || exit
1; \
215 ci-run-command@
%: ci-prepare-tree
216 $(CI_ENGINE
) run
$(CI_ENGINE_ARGS
) $(CI_IMAGE_PREFIX
)$*$(CI_IMAGE_TAG
) \
218 $(CI_USER_HOME)/prepare || exit 1; \
221 --user="#$(CI_UID)" \
222 --group="#$(CI_GID)" \
223 CI_CONT_SRCDIR="$(CI_CONT_SRCDIR)" \
224 CI_CONT_BUILDDIR="$(CI_CONT_BUILDDIR)" \
226 CI_CONFIGURE="$(CI_CONFIGURE)" \
227 CI_CONFIGURE_ARGS="$(CI_CONFIGURE_ARGS)" \
228 CI_MAKE_ARGS="$(CI_MAKE_ARGS)" \
229 $(CI_COMMAND) || exit 1'
230 @
test "$(CI_CLEAN)" = "1" && rm -rf
$(CI_SCRATCHDIR
) ||
:
233 $(MAKE
) -C
$(CI_ROOTDIR
) ci-run-command@
$* CI_COMMAND
="/bin/bash"
236 $(MAKE
) -C
$(CI_ROOTDIR
) ci-run-command@
$* CI_COMMAND
="$(CI_USER_HOME)/build"
239 $(MAKE
) -C
$(CI_ROOTDIR
) ci-build@
$* CI_MAKE_ARGS
="check"
242 @echo
"Build libvirt inside containers used for CI"
244 @echo
"Available targets:"
246 @echo
" ci-build@\$$IMAGE - run a default 'make'"
247 @echo
" ci-check@\$$IMAGE - run a 'make check'"
248 @echo
" ci-shell@\$$IMAGE - run an interactive shell"
250 @echo
"Available x86 container images:"
258 @echo
" fedora-rawhide"
262 @echo
"Available cross-compiler container images:"
264 @echo
" debian-{9,10,sid}-cross-aarch64"
265 @echo
" debian-{9,10,sid}-cross-armv6l"
266 @echo
" debian-{9,10,sid}-cross-armv7l"
267 @echo
" debian-{10,sid}-cross-i686"
268 @echo
" debian-{9,10,sid}-cross-mips64el"
269 @echo
" debian-{9,10,sid}-cross-mips"
270 @echo
" debian-{9,10,sid}-cross-mipsel"
271 @echo
" debian-{9,10,sid}-cross-ppc64le"
272 @echo
" debian-{9,10,sid}-cross-s390x"
274 @echo
"Available make variables:"
276 @echo
" CI_CLEAN=0 - do not delete '$(CI_SCRATCHDIR)' after completion"
277 @echo
" CI_REUSE=1 - re-use existing '$(CI_SCRATCHDIR)' content"
278 @echo
" CI_ENGINE=auto - container engine to use (podman, docker)"