ci: Stop using --workdir
[libvirt/ericb.git] / ci / Makefile
blob27c1049b38224e6720073d7c0523523deba5a0c0
1 # -*- makefile -*-
2 # vim: filetype=make
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.
26 CI_VPATH = build
28 # The directory holding the build output inside the
29 # container.
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
39 CI_MAKE_ARGS =
41 # Any extra arguments to pass to configure
42 CI_CONFIGURE_ARGS =
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
52 # image instead
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
61 CI_CLEAN = 1
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
66 # preserved env
67 CI_REUSE = 0
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")
79 CI_ENGINE = auto
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)
84 endif
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
89 # many tests.
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.
96 CI_PWDB_MOUNTS = \
97 --volume $(CI_SCRATCHDIR)/group:/etc/group:ro,z \
98 --volume $(CI_SCRATCHDIR)/passwd:/etc/passwd:ro,z \
99 $(NULL)
101 CI_HOME_MOUNTS = \
102 --volume $(CI_SCRATCHDIR)/home:$(CI_USER_HOME):z \
103 $(NULL)
105 CI_SCRIPT_MOUNTS = \
106 --volume $(CI_SCRATCHDIR)/prepare:$(CI_USER_HOME)/prepare:z \
107 --volume $(CI_SCRATCHDIR)/build:$(CI_USER_HOME)/build:z \
108 $(NULL)
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
122 # offset.
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
135 # work for everyone.
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),)
139 CI_MAX_UID = 65536
140 endif
141 ifeq ($(CI_MAX_GID),)
142 CI_MAX_GID = 65536
143 endif
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))))
149 CI_PODMAN_ARGS = \
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) \
156 $(NULL)
157 endif
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
163 CI_GIT_ARGS = \
164 -c advice.detachedHead=false \
165 -q \
166 --local \
167 $(NULL)
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
176 # --interactive
177 # --tty Ensure we have ability to Ctrl-C the build
178 CI_ENGINE_ARGS = \
179 --rm \
180 --interactive \
181 --tty \
182 $(CI_PODMAN_ARGS) \
183 $(CI_PWDB_MOUNTS) \
184 $(CI_HOME_MOUNTS) \
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 \
189 $(NULL)
191 ci-check-engine:
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') ; \
208 do \
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; \
212 done ; \
215 ci-run-command@%: ci-prepare-tree
216 $(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) \
217 /bin/bash -c ' \
218 $(CI_USER_HOME)/prepare || exit 1; \
219 sudo \
220 --login \
221 --user="#$(CI_UID)" \
222 --group="#$(CI_GID)" \
223 CI_CONT_SRCDIR="$(CI_CONT_SRCDIR)" \
224 CI_CONT_BUILDDIR="$(CI_CONT_BUILDDIR)" \
225 CI_SMP="$(CI_SMP)" \
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) || :
232 ci-shell@%:
233 $(MAKE) -C $(CI_ROOTDIR) ci-run-command@$* CI_COMMAND="/bin/bash"
235 ci-build@%:
236 $(MAKE) -C $(CI_ROOTDIR) ci-run-command@$* CI_COMMAND="$(CI_USER_HOME)/build"
238 ci-check@%:
239 $(MAKE) -C $(CI_ROOTDIR) ci-build@$* CI_MAKE_ARGS="check"
241 ci-help:
242 @echo "Build libvirt inside containers used for CI"
243 @echo
244 @echo "Available targets:"
245 @echo
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"
249 @echo
250 @echo "Available x86 container images:"
251 @echo
252 @echo " centos-7"
253 @echo " debian-9"
254 @echo " debian-10"
255 @echo " debian-sid"
256 @echo " fedora-29"
257 @echo " fedora-30"
258 @echo " fedora-rawhide"
259 @echo " ubuntu-16"
260 @echo " ubuntu-18"
261 @echo
262 @echo "Available cross-compiler container images:"
263 @echo
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"
273 @echo
274 @echo "Available make variables:"
275 @echo
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)"
279 @echo