vn-docker/image-build.sh

43 lines
802 B
Bash
Executable File

#!/bin/bash
set -e
MY_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$MY_DIR/image.conf"
# Prepare the environment
image=$1
version=$2
revision=$3
if [[ -z "$image" || -z "$version" ]]; then
echo "Usage: $0 <image> <version> [<revision>]"
exit 1
fi
tag="$version"
if [ ! -z "$revision" ]; then
tag="$tag-$revisionPrefix$revision"
fi
fullImage="$registry/$repository/$image"
latestImage="$fullImage:latest"
taggedImage="$fullImage:$tag"
echo "Image: $taggedImage"
read -p "Continue? (Default: no) [y|n]: " ANSWER
if [ "$ANSWER" != "y" ]; then
echo "Aborting push."
exit 3
fi
# Build and tag the image
docker build -t "$latestImage" "$image"
docker tag "$latestImage" "$taggedImage"
# Push the built image
docker push "$latestImage"
docker push "$taggedImage"