Skip to content
This repository has been archived by the owner on Nov 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from hypriot/add-create-debian-package
Browse files Browse the repository at this point in the history
Add creating of debian package
  • Loading branch information
DieterReuter committed Feb 25, 2015
2 parents 9a94fbc + ff5efb0 commit fdc0d4b
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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 /
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
68 changes: 60 additions & 8 deletions builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
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/
1 change: 1 addition & 0 deletions pkg-debian/DEBIAN/conffiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/default/docker
23 changes: 23 additions & 0 deletions pkg-debian/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions pkg-debian/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
if [ "$1" = "purge" ] ; then
update-rc.d docker remove >/dev/null
fi
5 changes: 5 additions & 0 deletions pkg-debian/DEBIAN/preinst
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions pkg-debian/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
if [ -x "/etc/init.d/docker" ]; then
invoke-rc.d docker stop || exit $?
fi
1 change: 1 addition & 0 deletions pkg-debian/debian-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0
2 changes: 1 addition & 1 deletion run-builder.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fdc0d4b

Please sign in to comment.