# HG changeset patch # User Gregory Szorc # Date 2018-05-12 22:51:37 # Node ID 11eda1f1b6e7b5e9bfb10e5e763823d399922aa8 # Parent 1cac2e8c76242e16c2da5f8e6d6efb76be592eba 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 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 && \ 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/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/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/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/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/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/dockerdeb b/contrib/packaging/dockerdeb --- a/contrib/packaging/dockerdeb +++ b/contrib/packaging/dockerdeb @@ -22,6 +22,8 @@ initcontainer $PLATFORM # 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/dockerlib.sh b/contrib/packaging/dockerlib.sh --- a/contrib/packaging/dockerlib.sh +++ b/contrib/packaging/dockerlib.sh @@ -26,17 +26,5 @@ function initcontainer() { [ -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/dockerrpm b/contrib/packaging/dockerrpm --- a/contrib/packaging/dockerrpm +++ b/contrib/packaging/dockerrpm @@ -16,6 +16,8 @@ RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM $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