diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 00000000..74904563 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu +# After installing the prerequisite we clear out sources.list so that +# 'apt-get update' doesn't do anything. +RUN sh -c 'apt-get -y update && apt-get -y install --no-install-recommends build-essential git ca-certificates golang docker.io mercurial libpcap-dev curl make pkg-config gcc bison flex && echo >/etc/apt/sources.list' +COPY build.sh / +ENTRYPOINT ["sh", "/build.sh"] diff --git a/build/build.sh b/build/build.sh new file mode 100644 index 00000000..68523397 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,44 @@ +#!/bin/sh +set -e + +GOPATH=/home/go +export GOPATH + +WEAVE_SRC=$GOPATH/src/github.com/zettio/weave + +if [ $# -eq 0 ] ; then + # No arguments. Expect that the weave repo will be bind-mounted + # into $GOPATH + if ! [ -e $WEAVE_SRC ] ; then + cat 2>&1 <:${GOPATH} \\ + -v /var/run/docker.sock:/var/run/docker.sock zettio/weave-build + +Or supply git clone arguments to retrieve it, e.g.: + + $ docker run -v /var/run/docker.sock:/var/run/docker.sock \\ + zettio/weave-build https://github.com/zettio/weave.git +EOF + exit 1 + fi + + # If we run make directly, any files created on the bind mount + # will have awkward ownership. So we switch to a user with the + # same user and group IDs as source directory. We have to set a + # few things up so that sudo works without complaining later on. + uid=$(stat --format="%u" $WEAVE_SRC) + gid=$(stat --format="%g" $WEAVE_SRC) + echo "weave:x:$uid:$gid::$WEAVE_SRC:/bin/sh" >>/etc/passwd + echo "weave:*:::::::" >>/etc/shadow + echo "weave ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers + su weave -c "make -C $WEAVE_SRC build" +else + # There are arguments to pass to git-clone + mkdir -p ${WEAVE_SRC%/*} + git clone "$@" $WEAVE_SRC + make -C $WEAVE_SRC build +fi