Browse Source

docker: create build-user with home directory in the container

This should mitigate issues with mapped /code not owned by UID 1000.
Helge Jung 9 years ago
parent
commit
3445f76a97
2 changed files with 24 additions and 36 deletions
  1. 17 33
      docker-build.sh
  2. 7 3
      docker/Dockerfile

+ 17 - 33
docker-build.sh

@@ -1,36 +1,20 @@
 #!/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
+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 BUILD_TS="$BUILD_TS" \
+    --env BASE="$BASE" \
+    --env BRANCH="$BRANCH" \
+    --env VERBOSE="$VERBOSE" \
+    --env VERSION="$VERSION" \
+    ffpb/build
+
+popd > /dev/null
 

+ 7 - 3
docker/Dockerfile

@@ -4,18 +4,22 @@ 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 \
+    faketime libfaketime libgmp-dev libmpfr-dev libmpc-dev \
     zlib1g-dev ncurses-dev
 
+RUN useradd -m build
+RUN sudo -Hu build git config --global user.name "docker-based build"
+RUN sudo -Hu build git config --global user.email "build@paderborn.freifunk.net"
+
 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
+ENV HOME /user/build
 USER build
 
-CMD ["/bin/bash", "docker-build.sh"]
+CMD ["/bin/bash", "build.sh"]