Browse Source

docker: ensure git-config is set up properly

Helge Jung 9 years ago
parent
commit
37b2d7de74
2 changed files with 20 additions and 4 deletions
  1. 17 0
      docker-build.sh
  2. 3 4
      docker/Dockerfile

+ 17 - 0
docker-build.sh

@@ -1,5 +1,22 @@
 #!/bin/bash
 
+# check if we're in the container
+running_in_docker() {
+  awk -F/ '$2 == "docker"' /proc/self/cgroup | read
+}
+
+# when called within the container, just call build.sh after ensuring git config is set
+if [ running_in_docker -a "$(id -un)" == "build" ]; 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 $@
+	exit
+fi
+
 MYDIR="$(dirname $0)"
 MYDIR="$(readlink -f $MYDIR)"
 pushd "$MYDIR" > /dev/null

+ 3 - 4
docker/Dockerfile

@@ -8,8 +8,8 @@ RUN apt-get update && apt-get install -y \
     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"
+ENV HOME /home/build
+RUN sudo -Hu build git config --global user.name "docker-based build" ; sudo -Hu build git config --global user.email "build@paderborn.freifunk.net"
 
 RUN mkdir /code
 WORKDIR /code
@@ -18,8 +18,7 @@ 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", "build.sh"]
+CMD ["/bin/bash", "docker-build.sh"]