push.sh: Add a helper script to mass-push repositories to a registry
authorW. Trevor King <wking@tremily.us>
Fri, 14 Feb 2014 20:35:32 +0000 (12:35 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 14 Feb 2014 20:49:36 +0000 (12:49 -0800)
For example, after building, if you want to upload all of the new
images.  Any repositories that already exist on the registry will just
be re-tagged.

push.sh [new file with mode: 0755]

diff --git a/push.sh b/push.sh
new file mode 100755 (executable)
index 0000000..447d50b
--- /dev/null
+++ b/push.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# Push all local repositories to a local registry
+#
+# Usage: ./push.sh docker-registry.example.com:5000
+
+REGISTRY="${1}"
+
+if [[ -z "${REGISTRY}" ]]
+then
+       echo "usage: ${0} REGISTRY" >&2
+       exit 1
+fi
+
+DOCKER_IO=$(command -v docker.io)
+DOCKER="${DOCKER:-${DOCKER_IO:-docker}}"
+
+while read REPOSITORY TAG HASH OTHER
+do
+       case "${REPOSITORY}" in
+       *none*|REPOSITORY)
+               continue  # not named or header line
+               ;;
+       "${REGISTRY}"/*)
+               continue  # already registered
+               ;;
+       esac
+       echo "${DOCKER}" tag -f "${HASH}" "${REGISTRY}/${REPOSITORY}:${TAG}" &&
+       "${DOCKER}" tag -f "${HASH}" "${REGISTRY}/${REPOSITORY}:${TAG}" &&
+       echo "${DOCKER}" push "${REGISTRY}/${REPOSITORY}"
+       "${DOCKER}" push "${REGISTRY}/${REPOSITORY}"
+done < <("${DOCKER}" images)