]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update dockerbuild script
authorMatthew Newton <matthew-git@newtoncomputing.co.uk>
Thu, 14 Dec 2017 21:43:46 +0000 (21:43 +0000)
committerMatthew Newton <matthew-git@newtoncomputing.co.uk>
Fri, 15 Dec 2017 22:42:49 +0000 (22:42 +0000)
scripts/docker/dockerbuild

index 33ebac50579e0463f197c599f01864d8744bab1d..fb3be4fd38270c68f728719458372f3761fe9792 100755 (executable)
@@ -6,24 +6,65 @@
 #  Example usage: ./dockerbuild build-debian9
 #
 
+usage ()
+{
+       [ "0$1" -gt 0 ] && exec 1>&2
+       echo "Syntax: $0 [options] <dir>"
+       echo "  -c      disable docker cache"
+       echo "  -j      build jenkins image instead of main image"
+       echo "  -l      build with clang rather than gcc"
+       echo "  -h      this help"
+       exit $1
+}
+
+OPT_CACHE=
+OPT_JENKINS=
+OPT_CC=gcc
+while getopts "chjl" OPT
+do
+       case $OPT in
+       c)      OPT_CACHE="--no-cache";;
+       h)      usage 0;;
+       j)      OPT_JENKINS=1;;
+       l)      OPT_CC=clang;;
+       *)      usage 1;;
+       esac
+done
+shift $(expr $OPTIND - 1)
+
 DIR="$1"
 
-[ -z "$DIR" ] && echo "Syntax: $0 <dir>" && exit 1
+[ -z "$DIR" ] && usage 1
 [ ! -d "$DIR" ] && echo "Directory '$DIR' does not exist" && exit 1
 
+#
+#  Work out which OS to base our image on from the dir name
+#
+DIR=$(echo "$DIR" | sed -e 's/\/$//')
 OSNAME=$(echo "$DIR" | sed -e 's/^build-//')
 
+#
+#  Build dependency image with compiler and all source ready to go
+#
 [ ! -r "$DIR/Dockerfile.deps" ] && echo "'$DIR/Dockerfile.deps' does not exist" && exit 1
 echo Building $OSNAME source and dependency image
-docker build "$DIR" -f "$DIR/Dockerfile.deps" -t freeradius/$OSNAME-deps
-
-if [ -r "$DIR/Dockerfile.jenkins" ]; then
-       echo Building $OSNAME jenkins image
-       docker build "$DIR" -f "$DIR/Dockerfile.jenkins" -t freeradius/$OSNAME-jenkins
-fi
+docker build $OPT_CACHE "$DIR" -f "$DIR/Dockerfile.deps" -t freeradius/$OSNAME-deps
 
-if [ -r "$DIR/Dockerfile" ]; then
-       echo Building $OSNAME FreeRADIUS image
-       docker build "$DIR" -t freeradius/$OSNAME
+if [ -n "$OPT_JENKINS" ]; then
+       #
+       #  Build jenkins image
+       #
+       if [ -r "$DIR/Dockerfile.jenkins" ]; then
+               echo Building $OSNAME jenkins image
+               docker build $OPT_CACHE "$DIR" -f "$DIR/Dockerfile.jenkins" -t freeradius/$OSNAME-jenkins
+       fi
+else
+       #
+       #  Build main image
+       #
+       if [ -r "$DIR/Dockerfile" ]; then
+               echo Building $OSNAME FreeRADIUS image
+               docker build --build-arg=cc=$OPT_CC $OPT_CACHE "$DIR" -t freeradius/$OSNAME
+       fi
 fi