59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
ARCH=()
|
|
VERSION_ARG=()
|
|
VERSION=""
|
|
REGISTRY=""
|
|
AZURITE_IMAGE="${AZURITE_IMAGE:-azurite:latest}"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--arch|-a)
|
|
ARCH+=("--arch" "$2")
|
|
shift 2
|
|
;;
|
|
--version|-v)
|
|
VERSION="$2"
|
|
VERSION_ARG+=("--build-arg" "VERSION=$VERSION")
|
|
shift 2
|
|
;;
|
|
--latest|-l)
|
|
VERSION="latest"
|
|
LATEST_TAG=$(git ls-remote --tags --refs --sort='v:refname' https://github.com/Azure/Azurite | tail -n1 | awk -F/ '{ print $3 }')
|
|
VERSION_ARG+=("--build-arg" "VERSION=$LATEST_TAG")
|
|
shift
|
|
;;
|
|
--registry|-r)
|
|
REGISTRY="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $1" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ ! -z "$REGISTRY" ]]; then
|
|
# Prepend the registry to the image name for tagging.
|
|
AZURITE_IMAGE="$REGISTRY/${AZURITE_IMAGE#*/}"
|
|
fi
|
|
|
|
if [[ -z "$VERSION" ]]; then
|
|
TAG_ARGS=("--tag" "${AZURITE_IMAGE%:*}:latest")
|
|
elif [[ "$VERSION" == "latest" ]]; then
|
|
TAG_ARGS=("--tag" "${AZURITE_IMAGE%:*}:${LATEST_TAG#v}" "--tag" "${AZURITE_IMAGE%:*}:latest")
|
|
else
|
|
TAG_ARGS=("--tag" "${AZURITE_IMAGE%:*}:${VERSION#v}")
|
|
fi
|
|
|
|
echo "Effective command line arguments:" ${ARCH[@]} ${VERSION_ARG[@]} ${TAG_ARGS[@]}
|
|
if command -v docker &> /dev/null; then
|
|
docker build "${ARCH[@]}" "${VERSION_ARG[@]}" "${TAG_ARGS[@]}" .
|
|
elif command -v container &> /dev/null; then
|
|
container build "${ARCH[@]}" "${VERSION_ARG[@]}" "${TAG_ARGS[@]}" .
|
|
else
|
|
echo "Neither supported container runtime found." >&2
|
|
exit 1
|
|
fi
|