From patchwork Tue Jul 12 15:00:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 71864 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp530149qga; Tue, 12 Jul 2016 08:17:26 -0700 (PDT) X-Received: by 10.55.164.205 with SMTP id n196mr3347196qke.73.1468336212688; Tue, 12 Jul 2016 08:10:12 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a61si2626800qtd.56.2016.07.12.08.10.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Jul 2016 08:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzK8-0001kv-3j for patch@linaro.org; Tue, 12 Jul 2016 11:10:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzBB-0008Mn-Nk for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:01:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMzB5-0007l6-IJ for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:00:57 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:36529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMzB5-0007ks-8o for qemu-devel@nongnu.org; Tue, 12 Jul 2016 11:00:51 -0400 Received: by mail-wm0-x22c.google.com with SMTP id f126so130758057wma.1 for ; Tue, 12 Jul 2016 08:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g8Ig/TJo+9Vt69qHA6BsrzVLLwQ/GzhBYJCVMfmJZDg=; b=ecTSoG2Tz9iWzEcVpgj3aalqs7drDAy0bT6qn5l59O8yBnQSXfM+jLCH1giJQcx5L3 lDh9xh7L5qewnAgts3zIwAMnsR/3IHsdikKPSW3wShi807T18i4jrqDHkkcSieph9ka3 XNqPR2hGShO13eSfrEpoPNc1n0pmx6atFnzyY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g8Ig/TJo+9Vt69qHA6BsrzVLLwQ/GzhBYJCVMfmJZDg=; b=ZjN69ybM3KzRA0ZdNkOViqjDRi2Q8AS7d2GmnWhe+AxTMDHBwpu3376reXSYX/i+JV hSglT5xlvwyyEzgMiXCh+mF5kxBx2IVMNYBqfbBdjOVyJrtz4cUsJINh6IV8zWPqTUCH 32bWU4SzKgMucytqQpC4YijC/gaXBBfFErXZLXJoKiC05y1sDHQyN/+/0kU1yv/yISwp rXWZ6Kcs/hfQ4TuX7snRbTp0s84KgDSNNmZsyAl5lFlOf1YUJd7KgcDlOHO5Ko1nJZuc IDJFMsf4tzWtq1hg1xNE4zSw87l22H/caPCc8A1MD0+dBv7RAfDZbhCk6gsBBMAcBGI6 tx9w== X-Gm-Message-State: ALyK8tLeCMi3/PH9U9shlIzM6s7sGYzPReF21r7kGSCask7sCYKL4/R2bAshG4PANQy3B1Os X-Received: by 10.28.232.149 with SMTP id f21mr3883357wmi.51.1468335650433; Tue, 12 Jul 2016 08:00:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f196sm29716525wmg.15.2016.07.12.08.00.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 08:00:47 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 351CD3E042B; Tue, 12 Jul 2016 16:00:49 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 12 Jul 2016 16:00:36 +0100 Message-Id: <1468335639-24582-5-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468335639-24582-1-git-send-email-alex.bennee@linaro.org> References: <1468335639-24582-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22c Subject: [Qemu-devel] [PATCH v5 4/7] tests/docker/dockerfiles: new debian-bootstrap.docker X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , riku.voipio@linaro.org, famz@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Together with the debian-bootstrap.pre script can now build an arbitrary architecture of Debian using debootstrap. This allows debootstrap to set up its first stage before the container is built. To build a container you need a command line like: DEB_ARCH=armhf DEB_TYPE=testing \ ./tests/docker/docker.py build \ --include-executable=arm-linux-user/qemu-arm debian:armhf \ ./tests/docker/dockerfiles/debian-bootstrap.docker Although a number of non-debian systems package the debootstrap script it is fairly portable in itself. Assuming we have some sort of fakeroot implementation we can just clone the upstream repository and use the script from there. Signed-off-by: Alex Bennée --- v2 - use .pre script instead of embedded HOST_CMD - make default image include all QEMU build-deps v3 - split docker.py from introduction of bootstrap v4 - handle no installed debootstrap [see BTS #830869] - add a bunch of pre-requisite checking (fakeroot, binfmt_misc) - add mapping from DEB_ARCH to QEMU_BIN --- tests/docker/dockerfiles/debian-bootstrap.docker | 21 ++++++ tests/docker/dockerfiles/debian-bootstrap.pre | 82 ++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/docker/dockerfiles/debian-bootstrap.docker create mode 100755 tests/docker/dockerfiles/debian-bootstrap.pre -- 2.7.4 diff --git a/tests/docker/dockerfiles/debian-bootstrap.docker b/tests/docker/dockerfiles/debian-bootstrap.docker new file mode 100644 index 0000000..3a9125e --- /dev/null +++ b/tests/docker/dockerfiles/debian-bootstrap.docker @@ -0,0 +1,21 @@ +# Create Debian Bootstrap Image +# +# This is intended to be pre-poluated by: +# - a first stage debootstrap (see debian-bootstrap.pre) +# - a native qemu-$arch that binfmt_misc will run +FROM scratch + +# Add everything from the context into the container +ADD . / + +# Patch all mounts as docker already has stuff set up +RUN sed -i 's/in_target mount/echo not for docker in_target mount/g' /debootstrap/functions + +# Run stage 2 +RUN /debootstrap/debootstrap --second-stage + +# At this point we can install additional packages if we want +# Duplicate deb line as deb-src +RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list +RUN apt-get update +RUN apt-get -y build-dep qemu diff --git a/tests/docker/dockerfiles/debian-bootstrap.pre b/tests/docker/dockerfiles/debian-bootstrap.pre new file mode 100755 index 0000000..ea12e2c --- /dev/null +++ b/tests/docker/dockerfiles/debian-bootstrap.pre @@ -0,0 +1,82 @@ +#!/bin/sh +# +# Simple wrapper for debootstrap, run in the docker build context +# +FAKEROOT=`which fakeroot 2> /dev/null` + +# +# fakeroot is needed to run the bootstrap stage +# +if [ -z $FAKEROOT ]; then + echo "Please install fakeroot to enable bootstraping" + exit 1 +fi + +# We check in order for +# +# - DEBOOTSTRAP_DIR pointing at a development checkout +# - PATH for the debootstrap script (installed) +# +# If neither option works then we checkout debootstrap from its +# upstream SCM and run it from there. +# + +if [ -z $DEBOOTSTRAP_DIR ]; then + DEBOOTSTRAP=`which debootstrap 2> /dev/null` + if [ -z $DEBOOTSTRAP ]; then + echo "No debootstrap installed, attempting to install from SCM" + DEBOOTSTRAP_SOURCE=https://anonscm.debian.org/git/d-i/debootstrap.git + git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git + export DEBOOTSTRAP_DIR=./debootstrap.git + DEBOOTSTRAP=./debootstrap.git/debootstrap + fi +else + DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap + if [ ! -f $DEBOOTSTRAP ]; then + echo "Couldn't find script at ${DEBOOTSTRAP}" + exit 2 + fi +fi + +# +# Finally check to see if any qemu's are installed +# +BINFMT_DIR=/proc/sys/fs/binfmt_misc +if [ ! -e $BINFMT_DIR ]; then + echo "binfmt_misc needs enabling for a QEMU bootstrap to work" + exit 3 +else + # DEB_ARCH and QEMU arch names are not totally aligned + case "${DEB_ARCH}" in + amd64) + QEMU=qemu-i386 + ;; + armel|armhf) + QEMU=qemu-arm + ;; + arm64) + QEMU=qemu-aarch64 + ;; + powerpc) + QEMU=qemu-ppc + ;; + ppc64el) + QEMU=qemu-ppc64le + ;; + s390) + QEMU=qemu-s390x + ;; + *) + QEMU=qemu-${DEB_ARCH} + ;; + esac + if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then + echo "No binfmt_misc rule to run $QEMU, can't bootstrap" + exit 4 + fi +fi + +echo "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP}" + +${FAKEROOT} ${DEBOOTSTRAP} --variant=buildd --foreign --arch=$DEB_ARCH $DEB_TYPE . http://httpredir.debian.org/debian +exit 0