fix: update entrypoint.sh to source accounts from accounts.env and improve Caddy handling

This commit is contained in:
2026-02-28 19:45:00 +01:00
parent 8813a4d5ed
commit b698521720

View File

@@ -6,13 +6,19 @@ 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
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"
ACCOUNT_NAME=$(echo "$AZURITE_ACCOUNTS" | cut -f 1 -d ';' | cut -f 1 -d ':')
@@ -29,6 +35,7 @@ cat <<EOF >> /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[@]}"