summaryrefslogtreecommitdiffstats
path: root/tests/docker/dockerfiles/debian-bootstrap.pre
diff options
context:
space:
mode:
authorAlex Bennée2016-07-19 15:20:39 +0200
committerFam Zheng2016-07-20 13:19:43 +0200
commit95c975013a15405a5ab257deae843ecd2eea20ec (patch)
tree9af73b1fb7de6d2e101034bf4b38915f8eeac251 /tests/docker/dockerfiles/debian-bootstrap.pre
parenttests/docker/docker.py: check and run .pre script (diff)
downloadqemu-95c975013a15405a5ab257deae843ecd2eea20ec.tar.gz
qemu-95c975013a15405a5ab257deae843ecd2eea20ec.tar.xz
qemu-95c975013a15405a5ab257deae843ecd2eea20ec.zip
tests/docker/dockerfiles: new debian-bootstrap.docker
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: 1468934445-32183-5-git-send-email-famz@redhat.com Signed-off-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'tests/docker/dockerfiles/debian-bootstrap.pre')
-rwxr-xr-xtests/docker/dockerfiles/debian-bootstrap.pre87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/docker/dockerfiles/debian-bootstrap.pre b/tests/docker/dockerfiles/debian-bootstrap.pre
new file mode 100755
index 0000000000..5d9c8d5ebc
--- /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} ${DEB_ARCH}/${DEB_TYPE}"
+
+${FAKEROOT} ${DEBOOTSTRAP} --variant=buildd --foreign --arch=$DEB_ARCH $DEB_TYPE . http://httpredir.debian.org/debian || exit 1
+exit 0