summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..35da7a3
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+img_name="$1"
+shift
+build_dir="$1"
+shift
+
+function print_usage {
+ echo ""
+ echo "Usage: $0 <image-name> <build-dir> [ .. <additional args to docker build> ]"
+ echo ""
+ echo " for example:"
+ echo " $0 docker.helsinki.at/debian:stretch debian/stretch/ --no-cache"
+ echo " will run:"
+ echo " docker build -t docker.helsinki.at/debian:stretch --no-cache debian/stretch/"
+ echo ""
+}
+
+if [ -z "$img_name" ] || [ -z "$build_dir" ]; then
+ print_usage
+ exit 1
+fi
+
+if [ ! -d "$build_dir" ]; then
+ echo "Error: '$build_dir' is not a directory"
+ exit 1
+fi
+
+set -e
+
+BASE_D="${BASH_SOURCE%/*}"
+STAGING_D=$(mktemp -d -t rh-docker-build.XXXX)
+
+function cleanup {
+ rm -rf "$STAGING_D"
+}
+trap cleanup EXIT
+
+cp -r "$build_dir" "$STAGING_D"
+BUILD_D="$STAGING_D"/$(basename "$build_dir")
+cp -r "$BASE_D/common" "$BUILD_D/"
+
+
+if [ "$UID" -ne 0 ]; then
+ exec sudo docker build -t "$img_name" "$@" "$BUILD_D"
+fi
+exec docker build -t "$img_name" "$@" "$BUILD_D"