packaging: allow running packaging with custom uid+gid for CentOS
rpmbuild in CentOS 7 has a bug causing rpmbuild to fail
with "Bad owner/group" if spec or source files are owned
by a different user: https://github.com/rpm-software-management/rpm/issues/2
This makes it very annoying to try and build the CentOS RPMs
on CentOS with Docker.
As an alternative, this change makes it possible to do so,
using an environment variable.
Differential Revision: https://phab.mercurial-scm.org/D5571
--- a/contrib/packaging/docker/centos5 Fri Jan 11 13:14:25 2019 +0100
+++ b/contrib/packaging/docker/centos5 Fri Jan 11 14:55:31 2019 +0100
@@ -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 && \
--- a/contrib/packaging/docker/centos6 Fri Jan 11 13:14:25 2019 +0100
+++ b/contrib/packaging/docker/centos6 Fri Jan 11 14:55:31 2019 +0100
@@ -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 \
--- a/contrib/packaging/docker/centos7 Fri Jan 11 13:14:25 2019 +0100
+++ b/contrib/packaging/docker/centos7 Fri Jan 11 14:55:31 2019 +0100
@@ -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 \
--- a/contrib/packaging/dockerrpm Fri Jan 11 13:14:25 2019 +0100
+++ b/contrib/packaging/dockerrpm Fri Jan 11 14:55:31 2019 +0100
@@ -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 $*
--- a/contrib/packaging/hg-docker Fri Jan 11 13:14:25 2019 +0100
+++ b/contrib/packaging/hg-docker Fri Jan 11 14:55:31 2019 +0100
@@ -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