diff --git a/Dockerfile b/Dockerfile index 40c1db7..ecc2025 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ RUN apt-get update && apt-get install -y \ btrfs-tools \ libsqlite3-dev \ libdevmapper-dev \ + fakeroot \ python-pip \ --no-install-recommends && \ rm -rf /var/lib/apt/lists/* @@ -21,8 +22,11 @@ RUN \ cd /src && \ git clone https://github.com/docker/docker.git -# Patch Docker for ARM 32bit +# Add Docker specific files ADD files/version.h /usr/include/btrfs/version.h +# Debian package template +ADD pkg-debian /pkg-debian + # Builder script COPY builder.sh / diff --git a/README.md b/README.md index 658bc3b..59b2bfc 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,5 @@ docker build -t hypriot/rpi-docker-builder . `./builder.sh` ```bash #!/bin/sh -x -docker run --rm=true --env-file=.env hypriot/rpi-docker-builder /builder.sh 1.5.0 +docker run --rm=true --env-file=.env -v $(pwd)/builder.sh:/builder.sh -v $(pwd)/pkg-debian:/pkg-debian hypriot/rpi-docker-builder /builder.sh 1.5.0 -7 ``` diff --git a/builder.sh b/builder.sh index 710c8e5..43bec67 100755 --- a/builder.sh +++ b/builder.sh @@ -3,19 +3,71 @@ set -e # set env var DOCKER_VERSION=$1 -ARCH_VERSION=armv6hf -TAR_FILE=docker-$DOCKER_VERSION-linux-$ARCH_VERSION.tar.gz -DEB_FILE=docker-$DOCKER_VERSION-linux-$ARCH_VERSION.deb +BUILD_REVISION=$2 -# compile Docker +# debian package versions +PACKAGE_NAME=docker-hypriot +PACKAGE_VERSION=$DOCKER_VERSION +PACKAGE_REVISION=$BUILD_REVISION +PACKAGE_ARCH=armhf +PACKAGE_ROOT=/pkg-debian +DEB_FILE=${PACKAGE_NAME}_${PACKAGE_VERSION}${PACKAGE_REVISION}_${PACKAGE_ARCH}.deb +TAR_FILE=${PACKAGE_NAME}-${DOCKER_VERSION}-${PACKAGE_REVISION}-${PACKAGE_ARCH}.tar.gz + +# compile Docker from source cd /src/docker git checkout v$DOCKER_VERSION export AUTO_GOPATH=1 GOARM=6 ./hack/make.sh dynbinary -# Create Debian package -cd / -tar czf $TAR_FILE -C /src/docker/bundles/$DOCKER_VERSION/dynbinary/ . +# create tarball with Docker binaries +tar czf /$TAR_FILE -C /src/docker/bundles/$DOCKER_VERSION/dynbinary/ . + +# create debian package +# --copy docker files +mkdir -p $PACKAGE_ROOT/etc/default/ +cp /src/docker/contrib/init/sysvinit-debian/docker.default $PACKAGE_ROOT/etc/default/docker +mkdir -p $PACKAGE_ROOT/etc/init.d/ +cp /src/docker/contrib/init/sysvinit-debian/docker $PACKAGE_ROOT/etc/init.d/docker +mkdir -p $PACKAGE_ROOT/lib/systemd/system/ +cp /src/docker/contrib/init/systemd/docker.service $PACKAGE_ROOT/lib/systemd/system/ +cp /src/docker/contrib/init/systemd/docker.socket $PACKAGE_ROOT/lib/systemd/system/ +mkdir -p $PACKAGE_ROOT/usr/bin/ +cp /src/docker/bundles/$DOCKER_VERSION/dynbinary/docker-$DOCKER_VERSION $PACKAGE_ROOT/usr/bin/docker +mkdir -p $PACKAGE_ROOT/usr/lib/docker/ +cp /src/docker/bundles/$DOCKER_VERSION/dynbinary/dockerinit-$DOCKER_VERSION $PACKAGE_ROOT/usr/lib/docker/dockerinit + +# --enable overlayfs by default +sed -i '/#DOCKER_OPTS/a \ +DOCKER_OPTS="--storage-driver=overlay -D"' $PACKAGE_ROOT/etc/default/docker + +# --get the total size of all package files +filesize=`du -sk /pkg-debian/ | cut -f1` +echo "Package size (uncompressed): $filesize kByte" + +# --create control file +cat << EOF > /pkg-debian/DEBIAN/control +Package: $PACKAGE_NAME +Version: $PACKAGE_VERSION$PACKAGE_REVISION +Architecture: $PACKAGE_ARCH +Maintainer: Dieter Reuter +Installed-Size: $filesize +Depends: adduser, iptables +Conflicts: docker.io +Replaces: docker.io +Recommends: ca-certificates, cgroupfs-mount | cgroup-lite, git, xz-utils +Section: admin +Priority: optional +Homepage: https://github.com/docker/docker +Description: Docker for ARM devices, compiled and packaged by http://blog.hypriot.com +EOF + +# --regenerate MD5 checksums for all files +(cd /pkg-debian; find . -type f ! -regex '.*.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' -printf '%P ' | xargs md5sum > DEBIAN/md5sums) + +# --use fakeroot to set owner/group to 0/0 (root/root) +fakeroot dpkg -b /pkg-debian/ /$DEB_FILE # Upload to S3 (using AWS CLI) -aws s3 cp $TAR_FILE s3://$AWS_BUCKET_NAME/docker/v$DOCKER_VERSION/ +aws s3 cp /$TAR_FILE s3://$AWS_BUCKET_NAME/docker/bin/ +aws s3 cp /$DEB_FILE s3://$AWS_BUCKET_NAME/docker/deb/ diff --git a/pkg-debian/DEBIAN/conffiles b/pkg-debian/DEBIAN/conffiles new file mode 100644 index 0000000..84e90fa --- /dev/null +++ b/pkg-debian/DEBIAN/conffiles @@ -0,0 +1 @@ +etc/default/docker diff --git a/pkg-debian/DEBIAN/postinst b/pkg-debian/DEBIAN/postinst new file mode 100755 index 0000000..8905a13 --- /dev/null +++ b/pkg-debian/DEBIAN/postinst @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +case "$1" in + configure) + if [ -z "$2" ]; then + if ! getent group docker > /dev/null 2>&1; then + addgroup --system --quiet docker + fi + fi + ;; + abort-*) + # How'd we get here?? + exit 1 + ;; + *) + ;; +esac + +if [ -x "/etc/init.d/docker" ]; then + update-rc.d docker defaults >/dev/null + invoke-rc.d docker start || exit $? +fi diff --git a/pkg-debian/DEBIAN/postrm b/pkg-debian/DEBIAN/postrm new file mode 100755 index 0000000..34c747a --- /dev/null +++ b/pkg-debian/DEBIAN/postrm @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ "$1" = "purge" ] ; then + update-rc.d docker remove >/dev/null +fi diff --git a/pkg-debian/DEBIAN/preinst b/pkg-debian/DEBIAN/preinst new file mode 100755 index 0000000..e0396f7 --- /dev/null +++ b/pkg-debian/DEBIAN/preinst @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -x "/etc/init.d/docker" ]; then + invoke-rc.d docker stop >/dev/null 2>&1 || exit 0 +fi diff --git a/pkg-debian/DEBIAN/prerm b/pkg-debian/DEBIAN/prerm new file mode 100755 index 0000000..b7b093c --- /dev/null +++ b/pkg-debian/DEBIAN/prerm @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -x "/etc/init.d/docker" ]; then + invoke-rc.d docker stop || exit $? +fi diff --git a/pkg-debian/debian-binary b/pkg-debian/debian-binary new file mode 100644 index 0000000..cd5ac03 --- /dev/null +++ b/pkg-debian/debian-binary @@ -0,0 +1 @@ +2.0 diff --git a/run-builder.sh b/run-builder.sh index 7afda92..3a036be 100755 --- a/run-builder.sh +++ b/run-builder.sh @@ -1,2 +1,2 @@ #!/bin/sh -x -docker run --rm=true --env-file=.env hypriot/rpi-docker-builder /builder.sh 1.5.0 +docker run --rm=true --env-file=.env -v $(pwd)/builder.sh:/builder.sh -v $(pwd)/pkg-debian:/pkg-debian hypriot/rpi-docker-builder /builder.sh 1.5.0 -7