From b69852172031976703f2ccb22dd7ade3c619e0bf Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Sat, 28 Feb 2026 19:45:00 +0100 Subject: [PATCH] fix: update entrypoint.sh to source accounts from accounts.env and improve Caddy handling --- entrypoint.sh | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f39d4e4..2810542 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,12 +6,18 @@ set -e . /app/cert-functions.sh # Setup default storage location, account name and accounts file path. -AZURITE_DIR="/storage" +AZURITE_STORAGE="${AZURITE_STORAGE:-/storage}" # Check, if the AZURITE_ACCOUNTS variable is set if [[ -z "$AZURITE_ACCOUNTS" ]]; then - # Generate a default account - export AZURITE_ACCOUNTS="devstoreaccount1:$(openssl rand -base64 32)" + if [[ -f "$AZURITE_STORAGE/accounts.env" ]]; then + set -a + source "$AZURITE_STORAGE/accounts.env" + set +a + else + # Generate a default account + export AZURITE_ACCOUNTS="devstoreaccount1:$(openssl rand -base64 32)" + fi fi # Look up the account name from the AZURITE_ACCOUNTS variable, which is in the format "accountName:accountKey1:accountKey2;accountName2:accountKey1:accountKey2" @@ -29,6 +35,7 @@ cat <> /etc/hosts EOF OAUTH_ARGS=() +NO_CADDY= while [[ $# -gt 0 ]]; do case "$1" in @@ -37,6 +44,10 @@ while [[ $# -gt 0 ]]; do # Ensure Caddy is disabled when using OAuth, as Azurite does not support OAuth behind a reverse proxy. shift ;; + --no-caddy) + NO_CADDY=true + shift + ;; *) echo "Unknown argument: $1" exit 1 @@ -45,20 +56,23 @@ while [[ $# -gt 0 ]]; do done # Ensure certificates are generated before starting Azurite or Caddy. -if ! make_ca "$AZURITE_DIR"; then +if ! make_ca "$AZURITE_STORAGE"; then echo "Error: Failed to create CA certificate and key." >&2 exit 1 fi -if ! make_server_cert "$ACCOUNT_NAME" "$AZURITE_DIR"; then +if ! make_server_cert "$ACCOUNT_NAME" "$AZURITE_STORAGE"; then echo "Error: Failed to create server certificate and key." >&2 exit 1 fi # Generate a Caddyfile configuration based on the account name and storage directory. -sed -E "s/__ACCOUNT_NAME__/${ACCOUNT_NAME}/g; s|__AZURITE_DIR__|${AZURITE_DIR}|g" /app/Caddyfile.example > "$AZURITE_DIR/Caddyfile" +sed -E "s/__ACCOUNT_NAME__/${ACCOUNT_NAME}/g; s|__AZURITE_STORAGE__|${AZURITE_STORAGE}|g" /app/Caddyfile.example > "$AZURITE_STORAGE/Caddyfile" -caddy start --config "$AZURITE_DIR/Caddyfile" # Use start not run, start does not block the shell process. +if [[ -z "$NO_CADDY" ]]; then + # Start Caddy in the background to handle HTTPS requests and route them to Azurite. + caddy start --config "$AZURITE_STORAGE/Caddyfile" # Use start not run, start does not block the shell process. +fi HOST_ARGS=("--blobHost" "127.0.0.1" "--queueHost" "127.0.0.1" "--tableHost" "127.0.0.1") PORT_ARGS=("--blobPort" "10000" "--queuePort" "10001" "--tablePort" "10002") @@ -66,6 +80,6 @@ PORT_ARGS=("--blobPort" "10000" "--queuePort" "10001" "--tablePort" "10002") # Start Azurite with the appropriate arguments based on the configuration. exec node /app/azurite/src/azurite.js \ --disableTelemetry \ - --location "$AZURITE_DIR" \ - --key "$AZURITE_DIR/${ACCOUNT_NAME}_key.pem" --cert "$AZURITE_DIR/${ACCOUNT_NAME}_cert.pem" \ + --location "$AZURITE_STORAGE" \ + --key "$AZURITE_STORAGE/${ACCOUNT_NAME}_key.pem" --cert "$AZURITE_STORAGE/${ACCOUNT_NAME}_cert.pem" \ "${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"