2019-01-25 16:28:23 +00:00
|
|
|
# -*- makefile -*-
|
|
|
|
# vim: filetype=make
|
|
|
|
|
2019-08-15 12:06:14 +00:00
|
|
|
# The root directory of the libvirt.git checkout
|
|
|
|
CI_GIT_ROOT = $(shell git rev-parse --show-toplevel)
|
|
|
|
|
|
|
|
# The root directory for all CI-related contents
|
|
|
|
CI_ROOTDIR = $(CI_GIT_ROOT)/ci
|
2019-01-25 16:28:23 +00:00
|
|
|
|
|
|
|
# The directory holding content on the host that we will
|
|
|
|
# expose to the container.
|
2019-08-15 12:06:14 +00:00
|
|
|
CI_SCRATCHDIR = $(CI_ROOTDIR)/scratch
|
2019-01-25 16:28:23 +00:00
|
|
|
|
|
|
|
# The directory holding the clone of the git repo that
|
|
|
|
# we will expose to the container
|
|
|
|
CI_HOST_SRCDIR = $(CI_SCRATCHDIR)/src
|
|
|
|
|
|
|
|
# The directory holding the source inside the
|
2019-05-07 15:37:39 +00:00
|
|
|
# container, i.e. where we want to expose
|
2019-01-25 16:28:23 +00:00
|
|
|
# the $(CI_HOST_SRCDIR) directory from the host
|
2019-08-15 18:52:07 +00:00
|
|
|
CI_CONT_SRCDIR = $(CI_USER_HOME)/libvirt
|
2019-01-25 16:28:23 +00:00
|
|
|
|
|
|
|
# Relative directory to perform the build in. This
|
|
|
|
# defaults to using a separate build dir, but can be
|
|
|
|
# set to empty string for an in-source tree build.
|
|
|
|
CI_VPATH = build
|
|
|
|
|
|
|
|
# The directory holding the build output inside the
|
|
|
|
# container.
|
|
|
|
CI_CONT_BUILDDIR = $(CI_CONT_SRCDIR)/$(CI_VPATH)
|
|
|
|
|
|
|
|
# Can be overridden with mingw{32,64}-configure if desired
|
|
|
|
CI_CONFIGURE = $(CI_CONT_SRCDIR)/configure
|
|
|
|
|
|
|
|
# Default to using all possible CPUs
|
|
|
|
CI_SMP = $(shell getconf _NPROCESSORS_ONLN)
|
|
|
|
|
|
|
|
# Any extra arguments to pass to make
|
|
|
|
CI_MAKE_ARGS =
|
|
|
|
|
|
|
|
# Any extra arguments to pass to configure
|
|
|
|
CI_CONFIGURE_ARGS =
|
|
|
|
|
2019-08-15 13:24:50 +00:00
|
|
|
# Script containing environment preparation steps
|
|
|
|
CI_PREPARE_SCRIPT = $(CI_ROOTDIR)/prepare.sh
|
|
|
|
|
2019-08-15 12:28:17 +00:00
|
|
|
# Script containing build instructions
|
|
|
|
CI_BUILD_SCRIPT = $(CI_ROOTDIR)/build.sh
|
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
# Location of the container images we're going to pull
|
2019-01-25 16:28:23 +00:00
|
|
|
# Can be useful to overridde to use a locally built
|
|
|
|
# image instead
|
2020-06-02 15:28:58 +00:00
|
|
|
CI_IMAGE_PREFIX = registry.gitlab.com/libvirt/libvirt/ci-
|
2019-01-25 16:28:23 +00:00
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
# The default tag is ':latest' but if the container
|
|
|
|
# repo above uses different conventions this can override it
|
2019-07-11 10:30:04 +00:00
|
|
|
CI_IMAGE_TAG = :latest
|
2019-01-25 16:28:23 +00:00
|
|
|
|
|
|
|
# We delete the virtual root after completion, set
|
|
|
|
# to 0 if you need to keep it around for debugging
|
|
|
|
CI_CLEAN = 1
|
|
|
|
|
|
|
|
# We'll always freshly clone the virtual root each
|
|
|
|
# time in case it was not cleaned up before. Set
|
|
|
|
# to 1 if you want to try restarting a previously
|
|
|
|
# preserved env
|
|
|
|
CI_REUSE = 0
|
|
|
|
|
|
|
|
# We need the container process to run with current host IDs
|
|
|
|
# so that it can access the passed in build directory
|
|
|
|
CI_UID = $(shell id -u)
|
|
|
|
CI_GID = $(shell id -g)
|
|
|
|
|
2019-08-15 18:34:20 +00:00
|
|
|
# We also need the user's login and home directory to prepare the
|
|
|
|
# environment the way some programs expect it
|
|
|
|
CI_USER_LOGIN = $(shell echo "$$USER")
|
|
|
|
CI_USER_HOME = $(shell echo "$$HOME")
|
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
CI_ENGINE = auto
|
|
|
|
# Container engine we are going to use, can be overridden per make
|
|
|
|
# invocation, if it is not we try podman and then default to docker.
|
|
|
|
ifeq ($(CI_ENGINE),auto)
|
|
|
|
override CI_ENGINE = $(shell podman version >/dev/null 2>&1 && echo podman || echo docker)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# IDs you run as do not need to exist in
|
2019-01-25 16:28:23 +00:00
|
|
|
# the container's /etc/passwd & /etc/group files, but
|
2019-05-07 15:37:39 +00:00
|
|
|
# if they do not, then libvirt's 'make check' will fail
|
2019-01-25 16:28:23 +00:00
|
|
|
# many tests.
|
2019-05-07 15:37:39 +00:00
|
|
|
|
2019-01-25 16:28:23 +00:00
|
|
|
# We do not directly mount /etc/{passwd,group} as Docker
|
|
|
|
# is liable to mess with SELinux labelling which will
|
2019-05-07 15:37:39 +00:00
|
|
|
# then prevent the host accessing them. And podman cannot
|
|
|
|
# relabel the files due to it running rootless. So
|
2019-08-08 14:31:40 +00:00
|
|
|
# copying them first is safer and less error-prone.
|
2019-01-25 16:28:23 +00:00
|
|
|
CI_PWDB_MOUNTS = \
|
|
|
|
--volume $(CI_SCRATCHDIR)/group:/etc/group:ro,z \
|
|
|
|
--volume $(CI_SCRATCHDIR)/passwd:/etc/passwd:ro,z \
|
|
|
|
$(NULL)
|
|
|
|
|
2019-08-15 18:34:20 +00:00
|
|
|
CI_HOME_MOUNTS = \
|
|
|
|
--volume $(CI_SCRATCHDIR)/home:$(CI_USER_HOME):z \
|
|
|
|
$(NULL)
|
|
|
|
|
2019-08-15 12:28:17 +00:00
|
|
|
CI_SCRIPT_MOUNTS = \
|
2019-08-15 13:24:50 +00:00
|
|
|
--volume $(CI_SCRATCHDIR)/prepare:$(CI_USER_HOME)/prepare:z \
|
2019-08-15 12:28:17 +00:00
|
|
|
--volume $(CI_SCRATCHDIR)/build:$(CI_USER_HOME)/build:z \
|
|
|
|
$(NULL)
|
|
|
|
|
2019-01-25 16:28:23 +00:00
|
|
|
# Docker containers can have very large ulimits
|
|
|
|
# for nofiles - as much as 1048576. This makes
|
|
|
|
# libvirt very slow at exec'ing programs.
|
|
|
|
CI_ULIMIT_FILES = 1024
|
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
ifeq ($(CI_ENGINE),podman)
|
2019-08-08 14:31:40 +00:00
|
|
|
# Podman cannot reuse host namespace when running non-root
|
|
|
|
# containers. Until support for --keep-uid is added we can
|
|
|
|
# just create another mapping that will do that for us.
|
|
|
|
# Beware, that in {uid,git}map=container_id:host_id:range, the
|
|
|
|
# host_id does actually refer to the uid in the first mapping
|
|
|
|
# where 0 (root) is mapped to the current user and rest is
|
|
|
|
# offset.
|
|
|
|
#
|
|
|
|
# In order to set up this mapping, we need to keep all the
|
|
|
|
# user IDs to prevent possible errors as some images might
|
|
|
|
# expect UIDs up to 90000 (looking at you fedora), so we don't
|
|
|
|
# want the overflowuid to be used for them. For mapping all
|
|
|
|
# the other users properly, some math needs to be done.
|
|
|
|
# Don't worry, it's just addition and subtraction.
|
|
|
|
#
|
|
|
|
# 65536 ought to be enough (tm), but for really rare cases the
|
|
|
|
# maximums might need to be higher, but that only happens when
|
|
|
|
# your /etc/sub{u,g}id allow users to have more IDs. Unless
|
|
|
|
# --keep-uid is supported, let's do this in a way that should
|
|
|
|
# work for everyone.
|
2019-08-15 18:34:20 +00:00
|
|
|
CI_MAX_UID = $(shell sed -n "s/^$(CI_USER_LOGIN):[^:]\+://p" /etc/subuid)
|
|
|
|
CI_MAX_GID = $(shell sed -n "s/^$(CI_USER_LOGIN):[^:]\+://p" /etc/subgid)
|
2019-05-07 15:37:39 +00:00
|
|
|
ifeq ($(CI_MAX_UID),)
|
|
|
|
CI_MAX_UID = 65536
|
|
|
|
endif
|
|
|
|
ifeq ($(CI_MAX_GID),)
|
|
|
|
CI_MAX_GID = 65536
|
|
|
|
endif
|
|
|
|
CI_UID_OTHER = $(shell echo $$(($(CI_UID)+1)))
|
|
|
|
CI_GID_OTHER = $(shell echo $$(($(CI_GID)+1)))
|
|
|
|
CI_UID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_UID)-$(CI_UID))))
|
|
|
|
CI_GID_OTHER_RANGE = $(shell echo $$(($(CI_MAX_GID)-$(CI_GID))))
|
|
|
|
|
|
|
|
CI_PODMAN_ARGS = \
|
|
|
|
--uidmap 0:1:$(CI_UID) \
|
|
|
|
--uidmap $(CI_UID):0:1 \
|
|
|
|
--uidmap $(CI_UID_OTHER):$(CI_UID_OTHER):$(CI_UID_OTHER_RANGE) \
|
|
|
|
--gidmap 0:1:$(CI_GID) \
|
|
|
|
--gidmap $(CI_GID):0:1 \
|
|
|
|
--gidmap $(CI_GID_OTHER):$(CI_GID_OTHER):$(CI_GID_OTHER_RANGE) \
|
|
|
|
$(NULL)
|
|
|
|
endif
|
|
|
|
|
2019-01-25 16:28:23 +00:00
|
|
|
# Args to use when cloning a git repo.
|
|
|
|
# -c stop it complaining about checking out a random hash
|
|
|
|
# -q stop it displaying progress info for local clone
|
|
|
|
# --local ensure we don't actually copy files
|
|
|
|
CI_GIT_ARGS = \
|
|
|
|
-c advice.detachedHead=false \
|
|
|
|
-q \
|
|
|
|
--local \
|
|
|
|
$(NULL)
|
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
# Args to use when running the container
|
2019-01-25 16:28:23 +00:00
|
|
|
# --rm stop inactive containers getting left behind
|
|
|
|
# --user we execute as the same user & group account
|
|
|
|
# as dev so that file ownership matches host
|
|
|
|
# instead of root:root
|
|
|
|
# --volume to pass in the cloned git repo & config
|
|
|
|
# --ulimit lower files limit for performance reasons
|
|
|
|
# --interactive
|
|
|
|
# --tty Ensure we have ability to Ctrl-C the build
|
2019-05-07 15:37:39 +00:00
|
|
|
CI_ENGINE_ARGS = \
|
2019-01-25 16:28:23 +00:00
|
|
|
--rm \
|
|
|
|
--interactive \
|
|
|
|
--tty \
|
2019-05-07 15:37:39 +00:00
|
|
|
$(CI_PODMAN_ARGS) \
|
2019-01-25 16:28:23 +00:00
|
|
|
$(CI_PWDB_MOUNTS) \
|
2019-08-15 18:34:20 +00:00
|
|
|
$(CI_HOME_MOUNTS) \
|
2019-08-15 12:28:17 +00:00
|
|
|
$(CI_SCRIPT_MOUNTS) \
|
2019-01-25 16:28:23 +00:00
|
|
|
--volume $(CI_HOST_SRCDIR):$(CI_CONT_SRCDIR):z \
|
|
|
|
--ulimit nofile=$(CI_ULIMIT_FILES):$(CI_ULIMIT_FILES) \
|
2019-08-15 14:28:31 +00:00
|
|
|
--cap-add=SYS_PTRACE \
|
2019-01-25 16:28:23 +00:00
|
|
|
$(NULL)
|
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
ci-check-engine:
|
|
|
|
@echo -n "Checking if $(CI_ENGINE) is available..." && \
|
|
|
|
$(CI_ENGINE) version 1>/dev/null && echo "yes"
|
2019-01-25 16:28:23 +00:00
|
|
|
|
2019-05-07 15:37:39 +00:00
|
|
|
ci-prepare-tree: ci-check-engine
|
2019-01-25 16:28:23 +00:00
|
|
|
@test "$(CI_REUSE)" != "1" && rm -rf $(CI_SCRATCHDIR) || :
|
|
|
|
@if ! test -d $(CI_SCRATCHDIR) ; then \
|
|
|
|
mkdir -p $(CI_SCRATCHDIR); \
|
|
|
|
cp /etc/passwd $(CI_SCRATCHDIR); \
|
|
|
|
cp /etc/group $(CI_SCRATCHDIR); \
|
2019-08-15 18:34:20 +00:00
|
|
|
mkdir -p $(CI_SCRATCHDIR)/home; \
|
2019-08-15 13:24:50 +00:00
|
|
|
cp "$(CI_PREPARE_SCRIPT)" $(CI_SCRATCHDIR)/prepare; \
|
2019-08-15 12:28:17 +00:00
|
|
|
cp "$(CI_BUILD_SCRIPT)" $(CI_SCRATCHDIR)/build; \
|
2019-08-15 13:24:50 +00:00
|
|
|
chmod +x "$(CI_SCRATCHDIR)/prepare" "$(CI_SCRATCHDIR)/build"; \
|
2019-01-25 16:28:23 +00:00
|
|
|
echo "Cloning $(CI_GIT_ROOT) to $(CI_HOST_SRCDIR)"; \
|
|
|
|
git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT) $(CI_HOST_SRCDIR) || exit 1; \
|
2019-08-15 12:06:14 +00:00
|
|
|
for mod in $$(git submodule | awk '{ print $$2 }' | sed -E 's,^../,,g') ; \
|
2019-01-25 16:28:23 +00:00
|
|
|
do \
|
|
|
|
test -f $(CI_GIT_ROOT)/$$mod/.git || continue ; \
|
|
|
|
echo "Cloning $(CI_GIT_ROOT)/$$mod to $(CI_HOST_SRCDIR)/$$mod"; \
|
|
|
|
git clone $(CI_GIT_ARGS) $(CI_GIT_ROOT)/$$mod $(CI_HOST_SRCDIR)/$$mod || exit 1; \
|
|
|
|
done ; \
|
|
|
|
fi
|
|
|
|
|
2019-08-15 13:23:23 +00:00
|
|
|
ci-run-command@%: ci-prepare-tree
|
2019-05-07 15:37:39 +00:00
|
|
|
$(CI_ENGINE) run $(CI_ENGINE_ARGS) $(CI_IMAGE_PREFIX)$*$(CI_IMAGE_TAG) \
|
2019-08-15 12:28:17 +00:00
|
|
|
/bin/bash -c ' \
|
2019-08-15 13:24:50 +00:00
|
|
|
$(CI_USER_HOME)/prepare || exit 1; \
|
2019-08-15 13:37:38 +00:00
|
|
|
sudo \
|
|
|
|
--login \
|
|
|
|
--user="#$(CI_UID)" \
|
|
|
|
--group="#$(CI_GID)" \
|
2020-02-10 17:02:55 +00:00
|
|
|
CONFIGURE_OPTS="$$CONFIGURE_OPTS" \
|
2019-08-15 13:37:38 +00:00
|
|
|
CI_CONT_SRCDIR="$(CI_CONT_SRCDIR)" \
|
|
|
|
CI_CONT_BUILDDIR="$(CI_CONT_BUILDDIR)" \
|
|
|
|
CI_SMP="$(CI_SMP)" \
|
|
|
|
CI_CONFIGURE="$(CI_CONFIGURE)" \
|
|
|
|
CI_CONFIGURE_ARGS="$(CI_CONFIGURE_ARGS)" \
|
|
|
|
CI_MAKE_ARGS="$(CI_MAKE_ARGS)" \
|
|
|
|
$(CI_COMMAND) || exit 1'
|
2019-01-25 16:28:23 +00:00
|
|
|
@test "$(CI_CLEAN)" = "1" && rm -rf $(CI_SCRATCHDIR) || :
|
|
|
|
|
2019-08-15 13:23:23 +00:00
|
|
|
ci-shell@%:
|
|
|
|
$(MAKE) -C $(CI_ROOTDIR) ci-run-command@$* CI_COMMAND="/bin/bash"
|
|
|
|
|
|
|
|
ci-build@%:
|
|
|
|
$(MAKE) -C $(CI_ROOTDIR) ci-run-command@$* CI_COMMAND="$(CI_USER_HOME)/build"
|
|
|
|
|
2019-01-25 16:28:23 +00:00
|
|
|
ci-check@%:
|
2019-08-15 12:06:14 +00:00
|
|
|
$(MAKE) -C $(CI_ROOTDIR) ci-build@$* CI_MAKE_ARGS="check"
|
2019-01-25 16:28:23 +00:00
|
|
|
|
2019-12-11 17:40:31 +00:00
|
|
|
ci-list-images:
|
|
|
|
@echo
|
|
|
|
@echo "Available x86 container images:"
|
|
|
|
@echo
|
2020-06-02 15:28:58 +00:00
|
|
|
@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep -v cross
|
2019-12-11 17:40:31 +00:00
|
|
|
@echo
|
|
|
|
@echo "Available cross-compiler container images:"
|
|
|
|
@echo
|
2020-06-02 15:28:58 +00:00
|
|
|
@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep cross
|
2019-12-11 17:40:31 +00:00
|
|
|
@echo
|
|
|
|
|
2019-01-25 16:28:23 +00:00
|
|
|
ci-help:
|
2019-05-07 15:37:39 +00:00
|
|
|
@echo "Build libvirt inside containers used for CI"
|
2019-01-25 16:28:23 +00:00
|
|
|
@echo
|
|
|
|
@echo "Available targets:"
|
|
|
|
@echo
|
|
|
|
@echo " ci-build@\$$IMAGE - run a default 'make'"
|
|
|
|
@echo " ci-check@\$$IMAGE - run a 'make check'"
|
|
|
|
@echo " ci-shell@\$$IMAGE - run an interactive shell"
|
2019-12-11 17:40:31 +00:00
|
|
|
@echo " ci-list-images - list available images"
|
|
|
|
@echo " ci-help - show this help message"
|
2019-01-25 16:28:23 +00:00
|
|
|
@echo
|
|
|
|
@echo "Available make variables:"
|
|
|
|
@echo
|
2019-05-07 15:37:39 +00:00
|
|
|
@echo " CI_CLEAN=0 - do not delete '$(CI_SCRATCHDIR)' after completion"
|
|
|
|
@echo " CI_REUSE=1 - re-use existing '$(CI_SCRATCHDIR)' content"
|
|
|
|
@echo " CI_ENGINE=auto - container engine to use (podman, docker)"
|
2019-01-25 16:28:23 +00:00
|
|
|
@echo
|