feat: enhance build and entrypoint scripts with improved argument handling and host entry management
This commit is contained in:
53
build.sh
53
build.sh
@@ -1,8 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ARCH=()
|
||||
VERSION_ARG=()
|
||||
VERSION=""
|
||||
REGISTRY=""
|
||||
|
||||
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
|
||||
IMAGE="azurite"
|
||||
else
|
||||
IMAGE="$REGISTRY/azurite"
|
||||
fi
|
||||
|
||||
if [[ -z "$VERSION" ]]; then
|
||||
TAG_ARGS=("--tag" "$IMAGE:latest")
|
||||
elif [[ "$VERSION" == "latest" ]]; then
|
||||
TAG_ARGS=("--tag" "$IMAGE:${LATEST_TAG#v}" "--tag" "$IMAGE:latest")
|
||||
else
|
||||
TAG_ARGS=("--tag" "$IMAGE:${VERSION#v}")
|
||||
fi
|
||||
|
||||
echo "Effective command line arguments:" ${ARCH[@]} ${VERSION_ARG[@]} ${TAG_ARGS[@]}
|
||||
if command -v dockerd &> /dev/null; then
|
||||
docker build -t azurite:latest .
|
||||
docker build "${ARCH[@]}" "${VERSION_ARG[@]}" "${TAG_ARGS[@]}" .
|
||||
elif command -v container &> /dev/null; then
|
||||
container build -t azurite:latest .
|
||||
container build "${ARCH[@]}" "${VERSION_ARG[@]}" "${TAG_ARGS[@]}" .
|
||||
else
|
||||
echo "Neither supported container runtime found." >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user