changeset 38457:11eda1f1b6e7

packaging: consistently create build user in Dockerfiles 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. Differential Revision: https://phab.mercurial-scm.org/D3758
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 12 May 2018 15:51:37 -0700
parents 1cac2e8c7624
children e5916f1236f3
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
diffstat 10 files changed, 33 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/packaging/docker/centos5	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/centos5	Sat May 12 15:51:37 2018 -0700
@@ -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 && \
--- a/contrib/packaging/docker/centos6	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/centos6	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/docker/centos7	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/centos7	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/docker/debian.template	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/debian.template	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/docker/fedora20	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/fedora20	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/docker/fedora21	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/fedora21	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/docker/ubuntu.template	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/docker/ubuntu.template	Sat May 12 15:51:37 2018 -0700
@@ -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 \
--- a/contrib/packaging/dockerdeb	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/dockerdeb	Sat May 12 15:51:37 2018 -0700
@@ -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"
--- a/contrib/packaging/dockerlib.sh	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/dockerlib.sh	Sat May 12 15:51:37 2018 -0700
@@ -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 -
 }
--- a/contrib/packaging/dockerrpm	Fri Jun 15 00:50:48 2018 +0530
+++ b/contrib/packaging/dockerrpm	Sat May 12 15:51:37 2018 -0700
@@ -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