Allow private docker registries

Change the sed seperator to accept a namespace with a private registry
and add an option to specify the registry. Below is an example for a
registry located at 192.168.0.10:5000.

$ ./build-all-docker-images -r 192.168.0.10:5000

The final image name would be something like this:
'192.168.0.10:5000/kollaglue/centos-rdo-base'

All build, push, and pull commands will still function the same.

Change-Id: Ic0ff96bb8119ddfab15b99e9f1e21cfe8d321dab
This commit is contained in:
Sam Yaple 2015-05-10 23:50:59 -05:00
parent 52847aa1b9
commit e057343c2f
2 changed files with 20 additions and 5 deletions

View File

@ -73,6 +73,7 @@ function init_image {
[ -f $WORKDIR/.buildconf ] && . $WORKDIR/.buildconf
[ -f $img_dir/.buildconf ] && . $img_dir/.buildconf
[ -n "$FORCE_NAMESPACE" ] && NAMESPACE=$FORCE_NAMESPACE
[ -n "${REGISTRY}" ] && NAMESPACE="${REGISTRY}/${NAMESPACE}"
local image="${NAMESPACE:+${NAMESPACE}/}${PREFIX}${img_dir##*/}"
local base_image=$(cat $img_dir/Dockerfile | gawk 'match($0, /^\s*FROM\s+(\S+)/, matches) {print matches[1]}' )
@ -136,7 +137,7 @@ trap 'interrupted' INT
ARGS=$@
PARSED_ARGS=$(getopt -q -o hn: -l help,namespace:,from:,to: -- "$@")
PARSED_ARGS=$(getopt -q -o hr:n: -l help,namespace:,private-registry:,from:,to: -- "$@")
eval set -- "$PARSED_ARGS"
@ -152,6 +153,11 @@ while :; do
FORCE_NAMESPACE="$1"
;;
(--private-registry|-r)
shift
REGISTRY="$1"
;;
(--from)
shift
FROM="$1"

View File

@ -15,6 +15,7 @@ Usage: $0 [options]
Options:
--private-registry, -r <registry_address[:port]>
--namespace, -n <namespace>
--tag, -t <tag>
--push, -p
@ -29,7 +30,7 @@ EOF
[ -f $TOPDIR/.buildconf ] && . $TOPDIR/.buildconf
[ -f $IMGDIR/.buildconf ] && . $IMGDIR/.buildconf
ARGS=$(getopt -o hn:t:pfuN -l help,namespace:,push,pull,release,tag:,force-rm,no-cache,no-use-released-parent -- "$@") || { usage >&2; exit 2; }
ARGS=$(getopt -o hr:n:t:pfuN -l help,namespace:,push,private-registry:,release,tag:,force-rm,no-cache,no-use-released-parent -- "$@") || { usage >&2; exit 2; }
eval set -- "$ARGS"
@ -63,6 +64,11 @@ while :; do
BUILDFLAGS="${BUILDFLAGS} --no-cache"
;;
(--private-registry|-r)
shift
REGISTRY="$1"
;;
(--namespace|-n)
shift
NAMESPACE="$1"
@ -94,6 +100,9 @@ if [ "$NAMESPACE" = "$RELEASE_NAMESPACE" ] \
exit 1
fi
if [[ -n $REGISTRY ]]; then
NAMESPACE="${REGISTRY}/${NAMESPACE}"
fi
IMAGE="${PREFIX}${IMGDIR##*/}"
FULLIMAGE="${NAMESPACE}/${IMAGE}${TAG:+:${TAG}}"
@ -113,9 +122,9 @@ TMPDIR=$(mktemp -d /tmp/kolla-build.XXXXXXXXXX)
cp -aL $IMGDIR/* $TMPDIR
# Use an extension for in-place editing for portability, as GNU and BSD
# versions of sed behave differently otherwise
sed -i.bak "s/%%KOLLA_NAMESPACE%%/${NAMESPACE}/g" $TMPDIR/Dockerfile
sed -i.bak "s/%%KOLLA_PREFIX%%/${PREFIX}/g" $TMPDIR/Dockerfile
sed -i.bak "s/%%KOLLA_TAG%%/${PARENT_TAG}/g" $TMPDIR/Dockerfile
sed -i.bak "s|%%KOLLA_NAMESPACE%%|${NAMESPACE}|g" $TMPDIR/Dockerfile
sed -i.bak "s|%%KOLLA_PREFIX%%|${PREFIX}|g" $TMPDIR/Dockerfile
sed -i.bak "s|%%KOLLA_TAG%%|${PARENT_TAG}|g" $TMPDIR/Dockerfile
if ! docker build ${BUILDFLAGS} -t "$FULLIMAGE" $TMPDIR; then
echo "ERROR: failed to build $FULLIMAGE"