Browse Source

rework docker build environment

To use the dockerized build, replace ./build.sh with ./docker-build.sh in your commandline.
The script constructs a container and starts it. In the container several environment parameters
are fixed:
  * the base OS: Ubuntu 14.04 LTS
  * the hostname: "ffpb-build"
  * the source directory: /code

In theory, this should be enough to get the same build output no matter where the firmware gets
compiled and/or by whom.
Helge Jung 9 years ago
parent
commit
2fca9e79a3
4 changed files with 58 additions and 13 deletions
  1. 1 0
      .gitignore
  2. 0 13
      Dockerfile
  3. 36 0
      docker-build.sh
  4. 21 0
      docker/Dockerfile

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
+/.*
 output
 src

+ 0 - 13
Dockerfile

@@ -1,13 +0,0 @@
-FROM ubuntu:14.04
-MAINTAINER hej@c3pb.de
-
-RUN apt-get update && apt-get install -y build-essential git python libfaketime libgmp-dev libmpfr-dev libmpc-dev
-RUN git config --global user.email build@paderborn.freifunk.net
-
-RUN mkdir /code
-WORKDIR /code
-
-RUN git clone https://git.c3pb.de/freifunk-pb/firmware.git .
-
-CMD ["/bin/bash", "build.sh"]
-

+ 36 - 0
docker-build.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# check if we're in the container
+if [ "$(id -un)" == "build" -a "$HOME" == "/code" ]; then
+
+	# ensure that we have a valid git config
+	git config --global user.name "docker-based build"
+	git config --global user.email build@paderborn.freifunk.net
+
+        # invoke the actual build
+	./build.sh $@
+
+else
+
+	# nope, it's the local system
+        MYDIR="$(dirname $0)"
+	MYDIR="$(readlink -f $MYDIR)"
+	pushd "$MYDIR" > /dev/null
+
+	# build the container (TODO: remove this, it should get pulled from the hub)
+	docker build -t ffpb/build docker
+
+        # run the container with fixed hostname and mapped /code directory
+	docker run -ti -h ffpb-build -v "$MYDIR:/code" \
+	  --env HOME=/code \
+          --env BUILD_TS="$BUILD_TS" \
+          --env BASE="$BASE" \
+          --env BRANCH="$BRANCH" \
+          --env VERBOSE="$VERBOSE" \
+          --env VERSION="$VERSION" \
+          ffpb/build
+
+	popd > /dev/null
+
+fi
+

+ 21 - 0
docker/Dockerfile

@@ -0,0 +1,21 @@
+FROM ubuntu:14.04
+MAINTAINER hej@c3pb.de
+
+RUN apt-get update && apt-get install -y \
+    build-essential \
+    git python wget gawk subversion unzip \
+    libfaketime libgmp-dev libmpfr-dev libmpc-dev \
+    zlib1g-dev ncurses-dev
+
+RUN mkdir /code
+WORKDIR /code
+
+RUN useradd -d /code build
+RUN chown -R build: /code
+RUN echo -en "#!/bin/sh\necho Start this container with "-v /path/to/firmware-repo:/code" to map your repo into it.\n" > /code/build.sh ; chmod +x /code/build.sh
+
+VOLUME /code
+USER build
+
+CMD ["/bin/bash", "docker-build.sh"]
+