Patchwork D5571: packaging: allow running packaging with custom uid+gid for CentOS

login
register
mail settings
Submitter phabricator
Date Jan. 14, 2019, 3:12 p.m.
Message ID <fb739bd02f0cc09f53946a2aecc98562@localhost.localdomain>
Download mbox | patch
Permalink /patch/37737/
State Not Applicable
Headers show

Comments

phabricator - Jan. 14, 2019, 3:12 p.m.
Mathiasdm updated this revision to Diff 13209.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5571?vs=13176&id=13209

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

AFFECTED FILES
  contrib/packaging/docker/centos5
  contrib/packaging/docker/centos6
  contrib/packaging/docker/centos7
  contrib/packaging/dockerrpm
  contrib/packaging/hg-docker

CHANGE DETAILS




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

Patch

diff --git a/contrib/packaging/hg-docker b/contrib/packaging/hg-docker
--- a/contrib/packaging/hg-docker
+++ b/contrib/packaging/hg-docker
@@ -47,7 +47,7 @@ 
         df = fh.read()
 
     for k, v in args:
-        df = df.replace(b'%%%s%%' % k, v)
+        df = df.replace(bytes('%%%s%%' % k.decode(), 'utf-8'), v)
 
     return df
 
diff --git a/contrib/packaging/dockerrpm b/contrib/packaging/dockerrpm
--- a/contrib/packaging/dockerrpm
+++ b/contrib/packaging/dockerrpm
@@ -10,7 +10,15 @@ 
 
 CONTAINER=hg-docker-$PLATFORM
 
-$BUILDDIR/hg-docker build $BUILDDIR/docker/$PLATFORM $CONTAINER
+if [[ -z "${HG_DOCKER_OWN_USER}" ]]; then
+    DOCKERUID=1000
+    DOCKERGID=1000
+else
+    DOCKERUID=$(id -u)
+    DOCKERGID=$(id -g)
+fi
+
+$BUILDDIR/hg-docker build --build-arg UID=$DOCKERUID --build-arg GID=$DOCKERGID $BUILDDIR/docker/$PLATFORM $CONTAINER
 
 RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM
 $ROOTDIR/contrib/packaging/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $*
diff --git a/contrib/packaging/docker/centos7 b/contrib/packaging/docker/centos7
--- a/contrib/packaging/docker/centos7
+++ b/contrib/packaging/docker/centos7
@@ -1,7 +1,7 @@ 
 FROM centos:centos7
 
-RUN groupadd -g 1000 build && \
-    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+RUN groupadd -g %GID% build && \
+    useradd -u %UID% -g %GID% -s /bin/bash -d /build -m build
 
 RUN yum install -y \
 	gcc \
diff --git a/contrib/packaging/docker/centos6 b/contrib/packaging/docker/centos6
--- a/contrib/packaging/docker/centos6
+++ b/contrib/packaging/docker/centos6
@@ -1,7 +1,7 @@ 
 FROM centos:centos6
 
-RUN groupadd -g 1000 build && \
-    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+RUN groupadd -g %GID% build && \
+    useradd -u %UID% -g %GID% -s /bin/bash -d /build -m build
 
 RUN yum install -y \
 	gcc \
diff --git a/contrib/packaging/docker/centos5 b/contrib/packaging/docker/centos5
--- a/contrib/packaging/docker/centos5
+++ b/contrib/packaging/docker/centos5
@@ -1,7 +1,7 @@ 
 FROM centos:centos5
 
-RUN groupadd -g 1000 build && \
-    useradd -u 1000 -g 1000 -s /bin/bash -d /build -m build
+RUN groupadd -g %GID% build && \
+    useradd -u %UID% -g %GID% -s /bin/bash -d /build -m build
 
 RUN \
 	sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/*.repo && \