[libvirt] [PATCH 0/3] Facilitate running libvirt builds via docker including cross-compilation

For a while QEMU has provided simple make rules for building QEMU inside standard docker container environments. This provides an equivalent mechanism for libvirt inspired by QEMU's. This series depends on the cross compiler images defined by: https://www.redhat.com/archives/libvir-list/2019-January/msg01039.html QEMU actually builds the container images on developer's machines locally. Libvirt already hosts pre-built images on quay.io, so that is used directly as it is quicker to download these than build them locally each time. Daniel P. Berrangé (3): tests: add targets for building libvirt inside docker containers tests: add cross compiler images to CI test help output tests: perform cross compiler builds on GitLab CI .gitignore | 1 + .gitlab-ci.yml | 38 ++++++++++++ Makefile.am | 2 + tests/Makefile.ci.inc | 134 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 tests/Makefile.ci.inc -- 2.20.1

The Travis CI system uses docker containers for its build environment. These are pre-built and hosted under quay.io/libvirt so that developers can use them for reproducing problems locally. Getting the right docker command syntax to use them, however, is not entirely easy. This patch addresses that usability issue by introducing some make targets make cibuild-fedora-28 will run a build of the local git repo using the buildenv-fedora-28 docker container, running the default make target in the container. make cibuild-fedora-28 will run "make check" while for more advanced debugging developers can get a direct shell and run any make command manually make cishell-fedora-28 In all cases the GIT source tree is cloned locally into a 'citree/src' sub-directory which is then exposed to the container at '/build'. It is setup to facilitate VPATH build so the initial working directory is '/build/vpath'. The make rules are kept in a standalone file that is included into the main Makefile.am, so that it is possible to run them without having to invoke autotools first. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- .gitignore | 1 + Makefile.am | 2 + tests/Makefile.ci.inc | 123 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 tests/Makefile.ci.inc diff --git a/.gitignore b/.gitignore index df0ac8e3d4..a7499bbbb6 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ /autom4te.cache /build-aux/* /build/ +/citree/ /confdefs.h /config.cache /config.guess diff --git a/Makefile.am b/Makefile.am index 709064c6a6..0c8ab13ebc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -123,3 +123,5 @@ gen-AUTHORS: mv -f $(distdir)/AUTHORS-tmp $(distdir)/AUTHORS && \ rm -f all.list maint.list contrib.list; \ fi + +include tests/Makefile.ci.inc diff --git a/tests/Makefile.ci.inc b/tests/Makefile.ci.inc new file mode 100644 index 0000000000..9deee91fd0 --- /dev/null +++ b/tests/Makefile.ci.inc @@ -0,0 +1,123 @@ +# -*- makefile -*- + +HERE = $(shell pwd) +TOP = $(shell git rev-parse --show-toplevel) + +# Default to using all possible CPUs +SMP = $(getconf _NPROCESSORS_ONLN) + +# Any extra arguments to pass to make +MAKE_ARGS = + +# Avoid pulling submodules over the network by locally +# cloning them +SUBMODULES = .gnulib src/keycodemapdb + +IMAGE_PREFIX = quay.io/libvirt/buildenv +IMAGE_TAG = :master + +# We delete the virtual root after completion, set +# to 0 if you need to keep it around for debugging +CLEAN = 1 + +# We'll always freshly clone the virtual root each +# time in case it was not cleaned up before. Set +# to 0 if you want to try restarting a previously +# preserved env +RECLONE = 1 + +SCRIPT = + +# We need the container process to run with current host IDs +# so that it can access the passed in build directory +UID = $(shell id -u) +GID = $(shell id -g) + +# Docker doesn't require the IDs you run as to exist in +# the container's /etc/passwd & /etc/group files, but +# if they do not, then libvirt's 'make check' will fail +# many tests +PWDB_MOUNTS = \ + --volume $(HERE)/citree/group:/etc/group:ro,z \ + --volume $(HERE)/citree/passwd:/etc/passwd:ro,z + +# Docker containers can have very large ulimits +# for nofiles - as much as 1048576. This makes +# libvirt very slow at exec'ing programs. +ULIMIT_FILES = 1024 + +DOCKER_ARGS = \ + --rm \ + --interactive \ + --tty \ + --user $(UID):$(GID) \ + $(PWDB_MOUNTS) \ + --volume $(HERE)/citree/src:/build:z \ + --workdir /build/vpath \ + --ulimit nofile=$(ULIMIT_FILES):$(ULIMIT_FILES) \ + $(NULL) + +preparetree: + @if test "$(RECLONE)" = "1" ; then \ + rm -rf citree ; \ + fi + @if ! test -d citree ; then \ + mkdir -p citree/src; \ + cp /etc/passwd citree; \ + cp /etc/group citree; \ + echo "Cloning $(TOP) to $(HERE)/citree/root"; \ + git clone -q --local $(TOP) $(HERE)/citree/src; \ + for mod in $(SUBMODULES) ; \ + do \ + echo "Cloning $(TOP)/$$mod to $(HERE)/citree/$$mod"; \ + git clone -q --local $(TOP)/$$mod $(HERE)/citree/src/$$mod ; \ + done ; \ + mkdir -p citree/src/vpath ; \ + else \ + test "$(CLEAN)" = "1" && rm -rf citree || : ; \ + fi + +# $LIBVIRT_CONFIGURE_OPTS is a env that can optionally be +# set in the container, populated at build time from the +# Dockerfile. A typical use case would be to pass --host/--target +# args to trigger cross-compilation +cibuild-%: preparetree + docker run $(DOCKER_ARGS) $(IMAGE_PREFIX)-$*$(IMAGE_TAG) \ + /bin/bash -c '\ + echo "../autogen.sh $${LIBVIRT_CONFIGURE_OPTS}" && \ + ../autogen.sh $${LIBVIRT_CONFIGURE_OPTS} && make -j $(SMP) $(MAKE_ARGS)' + @test "$(CLEAN)" = "1" && rm -rf citree || : + +cicheck-%: + $(MAKE) cibuild-$* MAKE_ARGS="check gl_public_submodule_commit=" + +cishell-%: preparetree + docker run $(DOCKER_ARGS) $(IMAGE_PREFIX)-$*$(IMAGE_TAG) /bin/bash + @test "$(CLEAN)" = "1" && rm -rf citree || : + +cihelp: + @echo "Build libvirt inside docker containers used for CI" + @echo + @echo "Available targets:" + @echo + @echo " cibuild-\$$IMAGE - run a default 'make'" + @echo " cicheck-\$$IMAGE - run a 'make check'" + @echo " cishell-\$$IMAGE - run an interactive shell" + @echo + @echo "Available container images:" + @echo + @echo " centos-7" + @echo " debian-8" + @echo " debian-9" + @echo " debian-sid" + @echo " fedora-28" + @echo " fedora-29" + @echo " fedora-rawhide" + @echo " ubuntu-16" + @echo " ubuntu-18" + @echo + @echo "Available make variables:" + @echo + @echo " CLEAN=0 - do not delete '$(HERE)/citree' after completion" + @echo " RECLONE=0 - re-use existing '$(HERE)/citree' content" + @echo -- 2.20.1

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/Makefile.ci.inc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.ci.inc b/tests/Makefile.ci.inc index 9deee91fd0..37f1455d03 100644 --- a/tests/Makefile.ci.inc +++ b/tests/Makefile.ci.inc @@ -104,7 +104,7 @@ cihelp: @echo " cicheck-\$$IMAGE - run a 'make check'" @echo " cishell-\$$IMAGE - run an interactive shell" @echo - @echo "Available container images:" + @echo "Available x86 native container images:" @echo @echo " centos-7" @echo " debian-8" @@ -116,6 +116,17 @@ cihelp: @echo " ubuntu-16" @echo " ubuntu-18" @echo + @echo "Available cross-compiler container images:" + @echo + @echo " cross-arm64" + @echo " cross-armel" + @echo " cross-armhf" + @echo " cross-mips64el" + @echo " cross-mips" + @echo " cross-mipsel" + @echo " cross-ppc64el" + @echo " cross-s390x" + @echo @echo "Available make variables:" @echo @echo " CLEAN=0 - do not delete '$(HERE)/citree' after completion" -- 2.20.1

GitLab CI provides some shared build runners that use Docker containers. This resource can usefully run cross-compiled builds since all other CI build testing is currently x86 only, and Travis CI is already very busy testing native builds. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- .gitlab-ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000..081d9d8f91 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,38 @@ +.job_template: &job_definition + script: + - mkdir vpath + - cd vpath + - ../autogen.sh $LIBVIRT_CONFIGURE_OPTS + - make -j $(getconf _NPROCESSORS_ONLN) + +crossarm64: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-arm64 + +crossarmel: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-armel + +crossarmhf: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-armhf + +crossmips64el: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mips64el + +crossmips: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mips + +crossmipsel: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mipsel + +crossppc64el: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-ppc64el + +crosss390x: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-s390x -- 2.20.1

On Mon, Jan 28, 2019 at 12:06:10PM +0000, Daniel P. Berrangé wrote:
GitLab CI provides some shared build runners that use Docker containers. This resource can usefully run cross-compiled builds since all other CI build testing is currently x86 only, and Travis CI is already very busy testing native builds.
You should be able to see the results of my tests with GitLab CI and cross-compiler builds here: https://gitlab.com/berrange/libvirt/pipelines/45067543 NB, I only created docker images for s390x & arm64, hence why only those 2 builds succeeded. Other note is that email notifications are enabled from the admin UI, not the .gitlab-ci.yml file, hence why this doesn't mention the libvirt-ci mailing list like travis.yml does.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- .gitlab-ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .gitlab-ci.yml
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000..081d9d8f91 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,38 @@ +.job_template: &job_definition + script: + - mkdir vpath + - cd vpath + - ../autogen.sh $LIBVIRT_CONFIGURE_OPTS + - make -j $(getconf _NPROCESSORS_ONLN) + +crossarm64: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-arm64 + +crossarmel: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-armel + +crossarmhf: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-armhf + +crossmips64el: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mips64el + +crossmips: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mips + +crossmipsel: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-mipsel + +crossppc64el: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-ppc64el + +crosss390x: + <<: *job_definition + image: quay.io/libvirt/buildenv-cross-s390x -- 2.20.1
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (1)
-
Daniel P. Berrangé