Add support to tag docker images when pushing them

This change adds an optional flag -t to docker/push-images.sh which
allows to specify a tag. Leaving it empty will omit adding a specific
tag and docker will fall back to "latest".

Testing: I tested this manually and confirmed that the flag works as
expected.

Change-Id: I370542127f190cc3e0be3facb3a0e691f101ef70
Reviewed-on: http://gerrit.cloudera.org:8080/13913
Reviewed-by: Lars Volker <lv@cloudera.com>
Tested-by: Lars Volker <lv@cloudera.com>
This commit is contained in:
Lars Volker
2019-07-24 16:19:30 -07:00
parent 8d4ba5d146
commit 12575f8abf

View File

@@ -33,6 +33,9 @@ usage() {
echo " Append this image prefix to all images pushed to the registry. Required."
echo " -r <registry>"
echo " Push to this registry. Optional, if not specified pushes to docker hub."
echo " -t <tag>"
echo " Append this tag to all images before pushing them, Optional, defaults to"
echo " empty."
echo
echo "Examples:"
echo "To push to some user's repository on Docker Hub, with names like "
@@ -42,7 +45,8 @@ usage() {
PREFIX=
REGISTRY=
while getopts "p:r:" OPTION
TAG=
while getopts "p:r:t:" OPTION
do
case "$OPTION" in
p)
@@ -51,6 +55,9 @@ do
r)
REGISTRY="$OPTARG"
;;
t)
TAG="$OPTARG"
;;
?)
echo "Unknown option."
usage
@@ -77,6 +84,9 @@ for IMAGE in ${IMAGES}; do
DEST=$REGISTRY/
fi
DEST+="$PREFIX-$IMAGE"
if [[ -n "$TAG" ]]; then
DEST+=":$TAG"
fi
docker image tag "$IMAGE" "$DEST"
docker push "$DEST"
done