Patchwork D3758: packaging: consistently create build user in Dockerfiles

login
register
mail settings
Submitter phabricator
Date June 16, 2018, 6:19 p.m.
Message ID <differential-rev-PHID-DREV-kri5jcg5c25gaomhizkp-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/32198/
State Superseded
Headers show

Comments

phabricator - June 16, 2018, 6:19 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Previously, dockerlib.sh appended some commands to create a
  "build" user in each Docker image. The resulting Docker images
  could be inconsistent depending on the execution environment
  and base image.
  
  With this change, we explicitly create our custom user and
  group as the first action in each Dockerfile. The user always
  has user:group 1000:1000 and all built images are consistent.
  
  We also create a home directory for the user under /build.
  This directory is currently ignored.
  
  As part of this, we stop setting the DBUILDUSER variable in
  dockerlib.sh and instead set it in the respective scripts that
  call it. This is in preparation for further refactoring of
  dockerlib.sh.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3758

AFFECTED FILES
  contrib/packaging/docker/centos5
  contrib/packaging/docker/centos6
  contrib/packaging/docker/centos7
  contrib/packaging/docker/debian.template
  contrib/packaging/docker/fedora20
  contrib/packaging/docker/fedora21
  contrib/packaging/docker/ubuntu.template
  contrib/packaging/dockerdeb
  contrib/packaging/dockerlib.sh
  contrib/packaging/dockerrpm

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/packaging/dockerrpm b/contrib/packaging/dockerrpm
--- a/contrib/packaging/dockerrpm
+++ b/contrib/packaging/dockerrpm
@@ -16,6 +16,8 @@ 
 $ROOTDIR/contrib/packaging/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $*
 
 DSHARED=/mnt/shared
+DBUILDUSER=build
+
 $DOCKER run -e http_proxy -e https_proxy -u $DBUILDUSER --rm -v $RPMBUILDDIR:$DSHARED $CONTAINER \
     rpmbuild --define "_topdir $DSHARED" -ba $DSHARED/SPECS/mercurial.spec --clean
 
diff --git a/contrib/packaging/dockerlib.sh b/contrib/packaging/dockerlib.sh
--- a/contrib/packaging/dockerlib.sh
+++ b/contrib/packaging/dockerlib.sh
@@ -26,17 +26,5 @@ 
   [ -f "$DFILE" ] || { echo "Error: docker file $DFILE not found"; exit 1; }
 
   CONTAINER="hg-dockerrpm-$1"
-  DBUILDUSER=build
-  (
-    cat $DFILE
-    if [ $(uname) = "Darwin" ] ; then
-        # The builder is using boot2docker on OS X, so we're going to
-        # *guess* the uid of the user inside the VM that is actually
-        # running docker. This is *very likely* to fail at some point.
-        echo RUN useradd $DBUILDUSER -u 1000
-    else
-        echo RUN groupadd $DBUILDUSER -g `id -g` -o
-        echo RUN useradd $DBUILDUSER -u `id -u` -g $DBUILDUSER -o
-    fi
-  ) | $DOCKER build --build-arg http_proxy --build-arg https_proxy --tag $CONTAINER -
+  cat $DFILE | $DOCKER build --build-arg http_proxy --build-arg https_proxy --tag $CONTAINER -
 }
diff --git a/contrib/packaging/dockerdeb b/contrib/packaging/dockerdeb
--- a/contrib/packaging/dockerdeb
+++ b/contrib/packaging/dockerdeb
@@ -22,6 +22,8 @@ 
 # container and hope it's writable. Whee.
 dn=$(basename $ROOTDIR)
 
+DBUILDUSER=build
+
 if [ $(uname) = "Darwin" ] ; then
     $DOCKER run -u $DBUILDUSER --rm -v $PWD/..:/mnt $CONTAINER \
             sh -c "cd /mnt/$dn && make clean && make local"
diff --git a/contrib/packaging/docker/ubuntu.template b/contrib/packaging/docker/ubuntu.template
--- a/contrib/packaging/docker/ubuntu.template
+++ b/contrib/packaging/docker/ubuntu.template
@@ -1,4 +1,8 @@ 
 FROM ubuntu:__CODENAME__
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN apt-get update && apt-get install -y \
   build-essential \
   debhelper \
diff --git a/contrib/packaging/docker/fedora21 b/contrib/packaging/docker/fedora21
--- a/contrib/packaging/docker/fedora21
+++ b/contrib/packaging/docker/fedora21
@@ -1,4 +1,8 @@ 
 FROM fedora:21
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN yum install -y \
 	gcc \
 	gettext \
diff --git a/contrib/packaging/docker/fedora20 b/contrib/packaging/docker/fedora20
--- a/contrib/packaging/docker/fedora20
+++ b/contrib/packaging/docker/fedora20
@@ -1,4 +1,8 @@ 
 FROM fedora:20
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN yum install -y \
 	gcc \
 	gettext \
diff --git a/contrib/packaging/docker/debian.template b/contrib/packaging/docker/debian.template
--- a/contrib/packaging/docker/debian.template
+++ b/contrib/packaging/docker/debian.template
@@ -1,4 +1,8 @@ 
 FROM debian:__CODENAME__
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN apt-get update && apt-get install -y \
   build-essential \
   debhelper \
diff --git a/contrib/packaging/docker/centos7 b/contrib/packaging/docker/centos7
--- a/contrib/packaging/docker/centos7
+++ b/contrib/packaging/docker/centos7
@@ -1,4 +1,8 @@ 
 FROM centos:centos7
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN yum install -y \
 	gcc \
 	gettext \
diff --git a/contrib/packaging/docker/centos6 b/contrib/packaging/docker/centos6
--- a/contrib/packaging/docker/centos6
+++ b/contrib/packaging/docker/centos6
@@ -1,4 +1,8 @@ 
 FROM centos:centos6
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN yum install -y \
 	gcc \
 	gettext \
diff --git a/contrib/packaging/docker/centos5 b/contrib/packaging/docker/centos5
--- a/contrib/packaging/docker/centos5
+++ b/contrib/packaging/docker/centos5
@@ -1,4 +1,8 @@ 
 FROM centos:centos5
+
+RUN groupadd -g 1000 build && \
+    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+
 RUN \
 	sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/*.repo && \
 	sed -i 's/^#\(baseurl=\)http:\/\/mirror.centos.org\/centos/\1http:\/\/vault.centos.org/' /etc/yum.repos.d/*.repo && \