From aa9274aca3d5e3c3a205cdf813fe4949e698339d Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Sat, 28 Feb 2026 10:36:36 +0100 Subject: [PATCH] feat: enhance build and entrypoint scripts with improved argument handling and host entry management --- build.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-- entrypoint.sh | 5 ++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 5383a72..a2574e6 100755 --- a/build.sh +++ b/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 diff --git a/entrypoint.sh b/entrypoint.sh index 3e969d9..f39d4e4 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 <> /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