From: "Alex Bennée" <alex.bennee@linaro.org>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v6 4/8] tests/docker/dockerfiles: new debian-bootstrap.docker
Date: Tue, 19 Jul 2016 10:00:27 +0100 [thread overview]
Message-ID: <87mvlem28k.fsf@linaro.org> (raw)
In-Reply-To: <1468916208-18668-5-git-send-email-famz@redhat.com>
Fam Zheng <famz@redhat.com> writes:
> From: Alex Bennée <alex.bennee@linaro.org>
>
> 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 <alex.bennee@linaro.org>
> Message-id: 1468335639-24582-5-git-send-email-alex.bennee@linaro.org
Acked-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> tests/docker/dockerfiles/debian-bootstrap.docker | 21 ++++++
> tests/docker/dockerfiles/debian-bootstrap.pre | 87 ++++++++++++++++++++++++
> 2 files changed, 108 insertions(+)
> create mode 100644 tests/docker/dockerfiles/debian-bootstrap.docker
> create mode 100755 tests/docker/dockerfiles/debian-bootstrap.pre
>
> 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..55850be
> --- /dev/null
> +++ b/tests/docker/dockerfiles/debian-bootstrap.pre
> @@ -0,0 +1,87 @@
> +#!/bin/sh
> +#
> +# Simple wrapper for debootstrap, run in the docker build context
> +#
> +FAKEROOT=`which fakeroot 2> /dev/null`
> +
> +exit_and_skip()
> +{
> + exit 3
> +}
> +
> +#
> +# fakeroot is needed to run the bootstrap stage
> +#
> +if [ -z $FAKEROOT ]; then
> + echo "Please install fakeroot to enable bootstraping"
> + exit_and_skip
> +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_and_skip
> + 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_and_skip
> +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_and_skip
> + 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 1
> +exit 0
--
Alex Bennée
next prev parent reply other threads:[~2016-07-19 9:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 8:16 [Qemu-devel] [PATCH v6 0/8] docker: Support building qemu-user powered docker test images Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 1/8] tests/docker/docker.py: docker_dir outside build Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 2/8] tests/docker/docker.py: support --include-executable Fam Zheng
2016-07-19 11:06 ` Daniel P. Berrange
2016-07-19 11:28 ` Alex Bennée
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 3/8] tests/docker/docker.py: check and run .pre script Fam Zheng
2016-07-19 9:29 ` Alex Bennée
2016-07-19 11:44 ` Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 4/8] tests/docker/dockerfiles: new debian-bootstrap.docker Fam Zheng
2016-07-19 9:00 ` Alex Bennée [this message]
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 5/8] tests/docker/docker.py: add update operation Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 6/8] docker: More sensible run script Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 7/8] docker: Fix exit code if $CMD failed Fam Zheng
2016-07-19 8:16 ` [Qemu-devel] [PATCH v6 8/8] docker: Don't start a container that doesn't exist Fam Zheng
2016-07-19 10:43 ` Alex Bennée
2016-07-19 9:58 ` [Qemu-devel] [PATCH v6 0/8] docker: Support building qemu-user powered docker test images Alex Bennée
2016-07-19 10:59 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mvlem28k.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=famz@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.