From 4553b7992412b96035551cec738c3da849bfb257 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 28 Nov 2016 16:38:37 +0000 Subject: [PATCH 12/12] travis-ci: Add and use infrastructure to build and test in Docker Debian stable, Debian testing and Ubuntu LTS provide a reasonable spectrum of old and new distributions. I'm only doing one build on each to avoid a combinatorial explosion of options. The Docker images don't have any deb-src apt sources set up, so don't use `apt-get build-dep`; just include dependencies manually. Signed-off-by: Simon McVittie --- .travis.yml | 6 ++++-- tools/ci-Dockerfile.in | 10 ++++++++++ tools/ci-build.sh | 16 ++++++++++++++++ tools/ci-install.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 tools/ci-Dockerfile.in diff --git a/.travis.yml b/.travis.yml index ca059e3..4ffc48c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,9 +23,8 @@ sudo: required dist: trusty language: c -install: - - ./tools/ci-install.sh script: + - ./tools/ci-install.sh # python-dbus and python-gi aren't available to Travis's version of # Python in /opt, which it uses as a default - PYTHON=/usr/bin/python ci_parallel=2 ci_sudo=yes ./tools/ci-build.sh @@ -39,5 +38,8 @@ env: - ci_host=mingw - ci_host=mingw ci_variant=debug - ci_host=mingw ci_buildsys=cmake + - ci_docker=ubuntu:xenial ci_distro=ubuntu ci_suite=xenial + - ci_docker=debian:jessie-slim ci_distro=debian ci_suite=jessie + - ci_docker=debian:stretch-slim ci_distro=debian ci_suite=stretch # vim:set sw=2 sts=2 et: diff --git a/tools/ci-Dockerfile.in b/tools/ci-Dockerfile.in new file mode 100644 index 0000000..e198b0d --- /dev/null +++ b/tools/ci-Dockerfile.in @@ -0,0 +1,10 @@ +FROM @ci_docker@ +ENV container docker + +ADD tools/ci-install.sh /ci-install.sh +RUN ci_suite="@ci_suite@" ci_distro="@ci_distro@" ci_in_docker=yes /ci-install.sh + +ADD . /home/user/ci +RUN chown -R user:user /home/user/ci +WORKDIR /home/user/ci +USER user diff --git a/tools/ci-build.sh b/tools/ci-build.sh index c3b4f49..35cf190 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -27,6 +27,7 @@ set -x NULL= : "${ci_buildsys:=autotools}" +: "${ci_docker:=}" : "${ci_host:=native}" : "${ci_parallel:=1}" : "${ci_sudo:=no}" @@ -34,6 +35,21 @@ NULL= : "${ci_test_fatal:=yes}" : "${ci_variant:=production}" +if [ -n "$ci_docker" ]; then + exec docker run \ + --env=ci_buildsys="${ci_buildsys}" \ + --env=ci_docker="" \ + --env=ci_host="${ci_host}" \ + --env=ci_parallel="${ci_parallel}" \ + --env=ci_sudo=yes \ + --env=ci_test="${ci_test}" \ + --env=ci_test_fatal="${ci_test_fatal}" \ + --env=ci_variant="${ci_variant}" \ + --privileged \ + ci-image \ + tools/ci-build.sh +fi + maybe_fail_tests () { if [ "$ci_test_fatal" = yes ]; then exit 1 diff --git a/tools/ci-install.sh b/tools/ci-install.sh index 596db58..b8c77ef 100755 --- a/tools/ci-install.sh +++ b/tools/ci-install.sh @@ -27,7 +27,9 @@ set -x NULL= : "${ci_distro:=ubuntu}" +: "${ci_docker:=}" : "${ci_host:=native}" +: "${ci_in_docker:=}" : "${ci_suite:=trusty}" if [ $(id -u) = 0 ]; then @@ -36,8 +38,25 @@ else sudo=sudo fi +if [ -n "$ci_docker" ]; then + sed \ + -e "s/@ci_distro@/${ci_distro}/" \ + -e "s/@ci_docker@/${ci_docker}/" \ + -e "s/@ci_suite@/${ci_suite}/" \ + < tools/ci-Dockerfile.in > Dockerfile + exec docker build -t ci-image . +fi + case "$ci_distro" in (debian|ubuntu) + # Don't ask questions, just do it + sudo="$sudo env DEBIAN_FRONTEND=noninteractive" + + # Debian Docker images use httpredir.debian.org but it seems to be + # unreliable; use a CDN instead + $sudo sed -i -e 's/httpredir\.debian\.org/deb.debian.org/g' \ + /etc/apt/sources.list + # travis-ci has a sources list for Chrome which doesn't support i386 : | $sudo tee /etc/apt/sources.list.d/google-chrome.list @@ -55,13 +74,13 @@ case "$ci_distro" in ${NULL} fi - $sudo apt-get -qq -y build-dep dbus - $sudo apt-get -qq -y install \ + autoconf-archive \ automake \ autotools-dev \ debhelper \ dh-autoreconf \ + dh-exec \ doxygen \ dpkg-dev \ gnome-desktop-testing \ @@ -76,6 +95,7 @@ case "$ci_distro" in python-dbus \ python-gi \ valgrind \ + wget \ xauth \ xmlto \ xsltproc \ @@ -83,6 +103,24 @@ case "$ci_distro" in ${NULL} case "$ci_suite" in + (trusty) + $sudo apt-get -qq -y install libsystemd-daemon-dev + ;; + (*) + $sudo apt-get -qq -y install libsystemd-dev + ;; + esac + + if [ -n "$ci_in_docker" ]; then + # Add the user that we will use to do the build inside the + # Docker container, and let them use sudo + adduser --disabled-password user /etc/sudoers.d/nopasswd + chmod 0440 /etc/sudoers.d/nopasswd + fi + + case "$ci_suite" in (trusty|jessie) wget http://snapshot.debian.org/archive/debian/20160905T163745Z/pool/main/a/autoconf-archive/autoconf-archive_20160320-1_all.deb $sudo dpkg -i autoconf-archive_*_all.deb -- 2.10.2