blob: f56172c0d10a4a72d4e4f6e0bf16a9fb9059f1f8 [file] [log] [blame]
#!/bin/bash
usage() {
me=`basename "$0"`
echo >&2 "Usage: $me [--help] [--tag TAG] [--gerrit-url URL] [IMAGE]"
exit 1
}
while test $# -gt 0 ; do
case "$1" in
--help)
usage
;;
--tag)
shift
TAG=$1
shift
;;
--gerrit-url)
shift
GERRIT_WAR_URL=$1
shift
;;
*)
break
esac
done
#Get list of images
source container-images/publish_list
IMAGES=$(get_image_list)
if test -n "$GERRIT_WAR_URL"; then
BUILD_ARGS="--build-arg GERRIT_WAR_URL=$GERRIT_WAR_URL"
fi
test -z "$TAG" && TAG=latest
export GIT_REV_TAG="$(git describe --always --dirty)-unknown"
docker_build(){
IMAGE=$1
docker build -t k8sgerrit/$IMAGE:$TAG \
-t k8sgerrit/$IMAGE:$GIT_REV_TAG \
./container-images/$IMAGE
if test $? -ne 0; then
REPORT="$REPORT Failed: k8sgerrit/$IMAGE.\n"
RETURN_CODE=1
else
REPORT="$REPORT Success: k8sgerrit/$IMAGE:$TAG\n Success: k8sgerrit/$IMAGE:$GIT_REV_TAG\n"
fi
}
docker_build_gerrit_base(){
docker build $BUILD_ARGS -t gerrit-base ./container-images/gerrit-base
if test $? -ne 0; then
echo -e "\n\nFailed to build gerrit-base image."
exit 1
fi
}
create_image_tag(){
GERRIT_VERSION=$(docker run --entrypoint "/bin/sh" gerrit-base \
-c "java -jar /var/gerrit/bin/gerrit.war version")
GERRIT_VERSION=$(echo "${GERRIT_VERSION##*$'\n'}" | cut -d' ' -f3 | tr -d '[:space:]')
GIT_REV_TAG="$(git describe --dirty)-$GERRIT_VERSION"
}
REPORT="Build results: \n"
RETURN_CODE=0
docker build -t base ./container-images/base
if test $? -ne 0; then
echo -e "\n\nFailed to build base image."
exit 1
fi
if test $# -eq 0 ; then
docker_build_gerrit_base
create_image_tag
for IMAGE in $IMAGES; do
docker_build $IMAGE
done
else
while test $# -gt 0 ; do
if [[ $1 = gerrit-* ]]; then
docker_build_gerrit_base
create_image_tag
else
echo -e "\nNo Image containing Gerrit will be built." \
"The Gerrit-version can thus not be determinded." \
"Using tag $GIT_REV_TAG\n"
fi
docker_build $1
shift
done
fi
echo -e "\n\n$REPORT"
exit $RETURN_CODE