Initial dockerfile commit
authorW. Trevor King <wking@tremily.us>
Wed, 11 Dec 2013 06:17:26 +0000 (22:17 -0800)
committerW. Trevor King <wking@tremily.us>
Wed, 11 Dec 2013 06:17:26 +0000 (22:17 -0800)
This builds a working Buildbot container from scratch using the Gentoo
stage3 tarball as a seed.  Everything seems to work with Docker
v0.7.1.

.gitignore [new file with mode: 0644]
README.md [new file with mode: 0644]
build.sh [new file with mode: 0755]
buildbot/Dockerfile.template [new file with mode: 0644]
buildbot/README.md [new file with mode: 0644]
downloads/.gitignore [new file with mode: 0644]
gentoo-en-us/Dockerfile.template [new file with mode: 0644]
gentoo-portage/Dockerfile.template [new file with mode: 0644]
gentoo-syslog/Dockerfile.template [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9414382
--- /dev/null
@@ -0,0 +1 @@
+Dockerfile
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..2bb4edc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,44 @@
+[Dockerfiles][] for assorted [Gentoo][]-based [Docker][] images.
+
+Dockerfiles are sorted into directories with names matching the
+suggested repository.  To avoid duplicating ephemeral data (namespace,
+timestamp tag, …), they appear in the `Dockerfile.template` as markers
+(`NAMESPACE`, `TAG`, …).  The `build.sh` script replaces the markers
+with values while generating a `Dockerfile` from each
+`Dockerfile.template`, and then builds each tag with:
+
+    $ docker build -t $NAMESPACE/$REPO:$TAG $REPO
+
+for example:
+
+    $ docker build -t wking/gentoo-en-us:20131205 gentoo-en-us
+
+The dependency graph is:
+
+    wking/gentoo  (amd64 stage3)
+    `-- gentoo-portage  (adds portage directory)
+        `-- gentoo-en-us  (adds locale)
+            `-- gentoo-syslog  (adds syslog-ng and associates)
+                `-- buildbot  (adds a Buildbot master and slave)
+
+Run:
+
+    $ ./build.sh
+
+to seed from the Gentoo mirrors and build all images.  There are a
+number of variables in the `build.sh` script that configure the build
+(`AUTHOR`, `NAMESPACE`, …).  We use [POSIX parameter
+expansion][parameter-expansion] to make it easy to override variables
+as you see fit.
+
+    $ NAMESPACE=jdoe DATE=20131210 ./build.sh
+
+I'd like to avoid bloating the images with the Portage tree, but
+without ugly hacks [that is not currently possible][3156] is mounted
+from the host.
+
+[Docker]: http://www.docker.io/
+[Dockerfiles]: http://www.docker.io/learn/dockerfile/
+[Gentoo]: http://www.gentoo.org/
+[parameter-expansion]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
+[3156]: https://github.com/dotcloud/docker/issues/3156
diff --git a/build.sh b/build.sh
new file mode 100755 (executable)
index 0000000..ad07013
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+AUTHOR="${AUTHOR:-W. Trevor King <wking@tremily.us>}"
+NAMESPACE="${NAMESPACE:-wking}"
+#PORTAGE="${PORTAGE:-/usr/portage}"
+DATE="${DATE:-20131205}"
+MIRROR="${MIRROR:-http://mirror.mcs.anl.gov/pub/gentoo/}"
+ARCH_URL="${ARCH_URL:-${MIRROR}/releases/amd64/current-stage3/}"
+STAGE3="${STAGE3:-stage3-amd64-${DATE}.tar.bz2}"
+STAGE3_CONTENTS="${STAGE3_CONTENTS:-${STAGE3}.CONTENTS}"
+STAGE3_DIGESTS="${STAGE3_DIGESTS:-${STAGE3}.DIGESTS.asc}"
+
+REPOS="
+       gentoo-portage
+       gentoo-en-us
+       gentoo-syslog
+       buildbot
+       "
+
+function die() {
+       echo "$1"
+       exit 1
+}
+
+STAGE3_IMAGES=$(docker images "${NAMESPACE}/gentoo")
+STAGE3_MATCHES=$(echo "${STAGE3_IMAGES}" | grep "${DATE}")
+if [ -z "${STAGE3_MATCHES}" ]; then
+       # import stage3 image from Gentoo mirrors
+
+       for FILE in "${STAGE3}" "${STAGE3_CONTENTS}" "${STAGE3_DIGESTS}"; do
+               if [ ! -f "downloads/${FILE}" ]; then
+                       wget -O "downloads/${FILE}" "${ARCH_URL}/${FILE}"
+               fi
+       done
+
+       gpg --verify "downloads/${STAGE3_DIGESTS}" || die "insecure digests"
+       SHA512_HASHES=$(grep -A1 SHA512 "downloads/${STAGE3_DIGESTS}" | grep -v '^--')
+       SHA512_CHECK=$(cd downloads/ && (echo "${SHA512_HASHES}" | sha512sum -c))
+       SHA512_FAILED=$(echo "${SHA512_CHECK}" | grep FAILED)
+       if [ -n "${SHA512_FAILED}" ]; then
+               die "${SHA512_FAILED}"
+       fi
+
+       docker import - "${NAMESPACE}/gentoo:${DATE}" < "downloads/${STAGE3}" || die "failed to import"
+fi
+
+docker tag -f "${NAMESPACE}/gentoo:${DATE}" "${NAMESPACE}/gentoo:latest" || die "failed to tag"
+
+for REPO in ${REPOS}; do
+       REPO_IMAGES=$(docker images "${NAMESPACE}/${REPO}")
+       REPO_MATCHES=$(echo "${REPO_IMAGES}" | grep "${DATE}")
+       if [ -z "${REPO_MATCHES}" ]; then
+               cp "${REPO}/Dockerfile.template" "${REPO}/Dockerfile"
+               sed -i "s|TAG|${DATE}|g" "${REPO}/Dockerfile"
+               sed -i "s|NAMESPACE|${NAMESPACE}|g" "${REPO}/Dockerfile"
+               sed -i "s|MAINTAINER.*|MAINTAINER ${AUTHOR}|g" "${REPO}/Dockerfile"
+               docker build -t "${NAMESPACE}/${REPO}:${DATE}" "${REPO}" || die "failed to build"
+       fi
+       docker tag -f "${NAMESPACE}/${REPO}:${DATE}" "${NAMESPACE}/${REPO}:latest" || die "failed to tag"
+done
diff --git a/buildbot/Dockerfile.template b/buildbot/Dockerfile.template
new file mode 100644 (file)
index 0000000..6b67ddb
--- /dev/null
@@ -0,0 +1,24 @@
+FROM NAMESPACE/gentoo-syslog:TAG
+MAINTAINER A. U. Thor <author@example.com>
+#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"]
+RUN echo 'USE="${USE} sqlite"' >> /etc/portage/make.conf
+RUN echo 'PYTHON_TARGETS="python2_7 python3_3"' >> /etc/portage/make.conf
+RUN echo 'PYTHON_SINGLE_TARGET="python3_3"' >> /etc/portage/make.conf
+RUN echo 'USE_PYTHON="2.7 3.3"' >> /etc/portage/make.conf
+RUN emerge -v1 --newuse dev-lang/python:2.7 dev-lang/python:3.3
+RUN emerge -v dev-util/buildbot dev-util/buildbot-slave
+RUN eselect news read new
+RUN rc-update add buildmaster default
+RUN rc-update add buildslave default
+
+# Container networking happens automatically
+RUN sed -i 's/need net$/use net/' /etc/init.d/*
+
+RUN buildbot create-master /var/lib/buildmaster
+RUN mv /var/lib/buildmaster/master.cfg.sample /var/lib/buildmaster/master.cfg
+RUN buildslave create-slave /var/lib/buildslave localhost:9989 example-slave pass
+RUN chown -R buildbot:buildbot /var/lib/buildmaster /var/lib/buildslave
+
+CMD rc default && tail -F /var/log/messages
+EXPOSE 8010
+EXPOSE 9989
diff --git a/buildbot/README.md b/buildbot/README.md
new file mode 100644 (file)
index 0000000..64e6c06
--- /dev/null
@@ -0,0 +1,9 @@
+Run this image with:
+
+    $ docker run -d -p 8010:8010 wking/buildbot
+
+it's currently just the default [Buildbot][] config, so there's
+nothing special to configure.  Browse to http://localhost:8010/ to see
+the web interface.
+
+[Buildbot]: http://buildbot.net/
diff --git a/downloads/.gitignore b/downloads/.gitignore
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
diff --git a/gentoo-en-us/Dockerfile.template b/gentoo-en-us/Dockerfile.template
new file mode 100644 (file)
index 0000000..01e5398
--- /dev/null
@@ -0,0 +1,8 @@
+FROM NAMESPACE/gentoo-portage:TAG
+MAINTAINER A. U. Thor <author@example.com>
+#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"]
+RUN echo en_US ISO-8859-1 > /etc/locale.gen
+RUN echo en_US.UTF-8 UTF-8 >> /etc/locale.gen
+RUN locale-gen
+RUN echo 'LANG="en_US.UTF-8"' >> /etc/env.d/02locale
+RUN env-update
diff --git a/gentoo-portage/Dockerfile.template b/gentoo-portage/Dockerfile.template
new file mode 100644 (file)
index 0000000..7b9233a
--- /dev/null
@@ -0,0 +1,8 @@
+FROM NAMESPACE/gentoo:TAG
+MAINTAINER A. U. Thor <author@example.com>
+RUN echo 'GENTOO_MIRRORS="http://mirror.mcs.anl.gov/pub/gentoo/"' >> /etc/portage/make.conf
+#RUN echo 'SYNC="rsync://rsync.us.gentoo.org"' >> /etc/portage/make.conf
+RUN mkdir -p /usr/portage
+RUN emerge-webrsync
+RUN emerge --sync --quiet
+RUN eselect news read new
diff --git a/gentoo-syslog/Dockerfile.template b/gentoo-syslog/Dockerfile.template
new file mode 100644 (file)
index 0000000..bcf66f4
--- /dev/null
@@ -0,0 +1,9 @@
+FROM NAMESPACE/gentoo-en-us:TAG
+MAINTAINER A. U. Thor <author@example.com>
+#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"]
+RUN emerge -v sys-process/vixie-cron app-admin/syslog-ng app-admin/logrotate
+RUN rc-update add syslog-ng default
+RUN rc-update add vixie-cron default
+
+# Disable logging to tty12
+RUN sed -i 's/\([^#].*console_all.*\)/#\1/' /etc/syslog-ng/syslog-ng.conf