Patchwork [2,of,6,packaging] dockerlib: extract initcontainer() method

login
register
mail settings
Submitter Augie Fackler
Date May 8, 2015, 5:10 p.m.
Message ID <3a363b17a66bb22e2951.1431105005@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/8972/
State Accepted
Headers show

Comments

Augie Fackler - May 8, 2015, 5:10 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1430923551 14400
#      Wed May 06 10:45:51 2015 -0400
# Node ID 3a363b17a66bb22e29513b12dea87275628c1416
# Parent  31cf06e694f031298e22adbdf202e7e1ae378881
dockerlib: extract initcontainer() method

This helps contain all the logic around creating containers.

Patch

diff --git a/contrib/dockerlib.sh b/contrib/dockerlib.sh
--- a/contrib/dockerlib.sh
+++ b/contrib/dockerlib.sh
@@ -17,3 +17,19 @@  function checkdocker() {
   $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; }
 }
+
+# Construct a container and leave its name in $CONTAINER for future use.
+function initcontainer() {
+  [ "$1" ] || { echo "Error: platform name must be specified"; exit 1; }
+
+  DFILE="$ROOTDIR/contrib/docker/$1"
+  [ -f "$DFILE" ] || { echo "Error: docker file $DFILE not found"; exit 1; }
+
+  CONTAINER="hg-dockerrpm-$1"
+  DBUILDUSER=build
+  (
+    cat $DFILE
+    echo RUN groupadd $DBUILDUSER -g `id -g`
+    echo RUN useradd $DBUILDUSER -u `id -u` -g $DBUILDUSER
+  ) | $DOCKER build --tag $CONTAINER -
+}
diff --git a/contrib/dockerrpm b/contrib/dockerrpm
--- a/contrib/dockerrpm
+++ b/contrib/dockerrpm
@@ -3,25 +3,14 @@ 
 . $(dirname $0)/dockerlib.sh
 
 BUILDDIR=$(dirname $0)
-ROOTDIR=$(cd $BUILDDIR/..; pwd)
+export ROOTDIR=$(cd $BUILDDIR/..; pwd)
 
 checkdocker
 
 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 -
+initcontainer $PLATFORM
 
 RPMBUILDDIR=$ROOTDIR/packages/$PLATFORM
 contrib/buildrpm --rpmbuilddir $RPMBUILDDIR --prepare $*