contrib/dockerrpm
author Pierre-Yves David <pierre-yves.david@fb.com>
Tue, 04 Nov 2014 10:40:06 +0000
changeset 23171 8afae1d5d108
parent 23124 4c490626af13
child 24968 80c9e99d68e0
permissions -rwxr-xr-x
perf: use a formatter for output We use a `formatter` object in the perf extensions. This allow the use of formatted output like json. To avoid adding logic to create a formatter and pass it around to the timer function in every command, we add a `gettimer` function in charge of returning a `timer` function as simple as before but embedding an appropriate formatter. This new `gettimer` function also return the formatter as it needs to be explicitly closed at the end of the command. example output: $ hg --config ui.formatjson=True perfvolatilesets visible obsolete [ { "comb": 0.02, "count": 126, "sys": 0.0, "title": "obsolete", "user": 0.02, "wall": 0.0199398994446 }, { "comb": 0.02, "count": 117, "sys": 0.0, "title": "visible", "user": 0.02, "wall": 0.0250301361084 } ]

#!/bin/bash -e

BUILDDIR=$(dirname $0)
ROOTDIR=$(cd $BUILDDIR/..; pwd)

if which docker.io >> /dev/null 2>&1 ; then
  DOCKER=docker.io
elif which docker >> /dev/null 2>&1 ; then
  DOCKER=docker
else
  echo "Error: docker must be installed"
  exit 1
fi

$DOCKER -h 2> /dev/null | grep -q Jansens && { echo "Error: $DOCKER is the Docking System Tray - install docker.io instead"; exit 1; }
$DOCKER version | grep -q "^Client version:" || { echo "Error: unexpected output from \"$DOCKER version\""; exit 1; }
$DOCKER version | grep -q "^Server version:" || { echo "Error: could not get docker server version - check it is running and your permissions"; exit 1; }

PLATFORM="$1"
[ "$PLATFORM" ] || { echo "Error: platform name must be specified"; exit 1; }
shift # extra params are passed to buildrpm

DFILE="$ROOTDIR/contrib/docker/$PLATFORM"
[ -f "$DFILE" ] || { echo "Error: docker file $DFILE not found"; exit 1; }

CONTAINER="hg-dockerrpm-$PLATFORM"

DBUILDUSER=build
(
cat $DFILE
echo RUN groupadd $DBUILDUSER -g `id -g`
echo RUN useradd $DBUILDUSER -u `id -u` -g $DBUILDUSER
) | $DOCKER build --tag $CONTAINER -

RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM
contrib/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $*

DSHARED=/mnt/shared
$DOCKER run -u $DBUILDUSER --rm -v $RPMBUILDDIR:$DSHARED $CONTAINER \
    rpmbuild --define "_topdir $DSHARED" -ba $DSHARED/SPECS/mercurial.spec --clean

$DOCKER run -u $DBUILDUSER --rm -v $RPMBUILDDIR:$DSHARED $CONTAINER \
    createrepo $DSHARED

cat << EOF > $RPMBUILDDIR/mercurial.repo
# Place this file in /etc/yum.repos.d/mercurial.repo
[mercurial]
name=Mercurial packages for $PLATFORM
# baseurl=file://$RPMBUILDDIR/
baseurl=http://hg.example.com/build/$PLATFORM/
skip_if_unavailable=True
gpgcheck=0
enabled=1
EOF

echo
echo "Build complete - results can be found in $RPMBUILDDIR"