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
|
||||
|
||||
@@ -19,7 +19,10 @@ ACCOUNT_NAME=$(echo "$AZURITE_ACCOUNTS" | cut -f 1 -d ';' | cut -f 1 -d ':')
|
||||
|
||||
# Ensure /etc/hosts contains an entry the Azure endpoint names,
|
||||
# so Caddy can route requests to the correct service based on the hostname.
|
||||
sed -i -E "/${ACCOUNT_NAME}/d" /etc/hosts
|
||||
if grep -q "${ACCOUNT_NAME}" /etc/hosts; then
|
||||
cp -a /etc/hosts /etc/hosts.bak && sed -E "/${ACCOUNT_NAME}/d" /etc/hosts > /etc/hosts
|
||||
fi
|
||||
|
||||
cat <<EOF >> /etc/hosts
|
||||
|
||||
127.0.0.1 ${ACCOUNT_NAME}.blob.core.windows.net ${ACCOUNT_NAME}.queue.core.windows.net ${ACCOUNT_NAME}.table.core.windows.net ${ACCOUNT_NAME}.blob.localhost ${ACCOUNT_NAME}.queue.localhost ${ACCOUNT_NAME}.table.localhost
|
||||
|
||||
Reference in New Issue
Block a user