kolla/tools/build-docker-image
Alicja Kwasniewska fcda6a06d8 Keystone installation from source
Makes use of new gen-source-tar script to provide a source based
keystone image.

This patch introduces a new concept of a .buildinfo file, which provides
variables specific to the image being built which cannot be defaulted in
a generic way, at least until the build script is overhauled. This file
is sourced before the .buildconf which still leaves everything
customisable by the user.

Co-Authored-By: Paul Bourke <paul.bourke@oracle.com>
Change-Id: I0ec6b9cfe6d4173f3192e4ae5833fb0f6d333f1c
Implements: blueprint install-from-source
2015-07-09 11:06:58 +00:00

184 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root. Instead add yourself to the docker group." 1>&2
exit 1
fi
TOPDIR=$(git rev-parse --show-toplevel)
IMGDIR="$(cd "$(dirname "$0")" && pwd)"
RELEASE_NAMESPACE=kollaglue
NAMESPACE=kollaglue
PREFIX=centos-rdo-
TAG=$(git rev-parse --short HEAD)
RELEASE_TAG=latest
MAX_TRIES=1
usage () {
cat <<EOF
Usage: $0 [options]
Options:
--prefix <image_prefix>
--private-registry, -r <registry_address[:port]>
--namespace, -n <namespace>
--tag, -t <tag>
--push, -p
--force-rm, -f
--no-cache, -N
--pull, -u
--release
--no-use-released-parent
--retry <number_of_retries>
EOF
}
[ -f $TOPDIR/.buildconf ] && . $TOPDIR/.buildconf
[ -f $IMGDIR/.buildinfo ] && . $IMGDIR/.buildinfo
[ -f $IMGDIR/.buildconf ] && . $IMGDIR/.buildconf
ARGS=$(getopt -o hr:n:t:pfuN -l help,prefix:,namespace:,push,pull,private-registry:,release,tag:,force-rm,no-cache,no-use-released-parent,retry: -- "$@") || { usage >&2; exit 2; }
eval set -- "$ARGS"
while :; do
case "$1" in
(--help|-h) usage
exit 0
;;
(--prefix) shift
FORCE_PREFIX="$1"
;;
(--release) MODE=release
NAMESPACE=$RELEASE_NAMESPACE
TAG=$RELEASE_TAG
;;
(--tag|-t) shift
TAG="$1"
;;
(--push|-p) PUSH=1
;;
(--pull|-u) BUILDFLAGS="${BUILDFLAGS} --pull=true"
;;
(--force-rm|-f)
BUILDFLAGS="${BUILDFLAGS} --force-rm=true"
;;
(--no-cache|-N)
BUILDFLAGS="${BUILDFLAGS} --no-cache"
;;
(--private-registry|-r)
shift
REGISTRY="$1"
;;
(--namespace|-n)
shift
NAMESPACE="$1"
;;
(--no-use-released-parent)
USE_CURRENT_TAG=1
;;
(--retry)
shift
MAX_TRIES=$((MAX_TRIES + $1))
;;
(--) break
;;
esac
shift
done
if [[ $USE_CURRENT_TAG = 1 ]]; then
PARENT_TAG=$TAG
else
PARENT_TAG=$RELEASE_TAG
fi
if [ "$NAMESPACE" = "$RELEASE_NAMESPACE" ] \
&& [ "$TAG" = "$RELEASE_TAG" ] \
&& ! [ "$MODE" = "release" ]; then
echo "ERROR: use --release to build a release image" >&2
exit 1
fi
if [[ -n "${PREFIX}" && -n "${FORCE_PREFIX}" ]]; then
PREFIX="${FORCE_PREFIX}"
fi
if [[ -n $REGISTRY ]]; then
NAMESPACE="${REGISTRY}/${NAMESPACE}"
fi
IMAGE="${PREFIX}${IMGDIR##*/}"
FULLIMAGE="${NAMESPACE}/${IMAGE}${TAG:+:${TAG}}"
cat <<EOF
======================================================================
$FULLIMAGE
======================================================================
EOF
if [ "$MODE" = "release" ]; then
echo "*** YOU ARE BUILDING A RELEASE IMAGE ***"
echo
fi
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
if [[ "${SOURCE_INSTALL_AVAILABLE}" == "1" ]]; then
. ${TOPDIR}/tools/gen-source-tar.sh
fi
TRY=0
while [ $((MAX_TRIES - 1)) -gt $TRY ]; do
if docker build ${BUILDFLAGS} -t "$FULLIMAGE" $TMPDIR; then
break
else
echo "WARNING: failed to build $FULLIMAGE, retrying..."
TRY=$((TRY + 1))
fi
done
if ! docker build ${BUILDFLAGS} -t "$FULLIMAGE" $TMPDIR; then
echo "ERROR: failed to build $FULLIMAGE"
exit 1
fi
rm -rf $TMPDIR
echo "Built: $FULLIMAGE"
if [ "$PUSH" = 1 ]; then
if ! docker push "$FULLIMAGE"; then
echo "ERROR: failed to push $FULLIMAGE"
exit 1
fi
echo "Pushed: $FULLIMAGE"
fi