#!/bin/bash set -euo pipefail # Check, if the AZURITE_ACCOUNTS variable is set if [[ -z "$AZURITE_ACCOUNTS" ]]; then echo "Error: AZURITE_ACCOUNTS variable is not set." >&2 exit 1 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 ':') # Check, if the certificate for the account exists. if [[ ! -f "/storage/${ACCOUNT_NAME}_cert.pem" ]] || [[ ! -f "/storage/${ACCOUNT_NAME}_key.pem" ]]; then echo "[ERROR] Certificate or key for account ${ACCOUNT_NAME} not found." exit 1 fi OAUTH_ARGS=("--oauth" "basic") NO_CADDY= while [[ $# -gt 0 ]]; do case "$1" in --no-oauth) OAUTH_ARGS=() shift ;; --no-caddy) NO_CADDY=true shift ;; *) echo "Unknown argument: $1" exit 1 ;; esac done if [[ -z "$NO_CADDY" ]]; then # Generate a Caddyfile configuration based on the account name and storage directory. sed -E "s/__ACCOUNT_NAME__/${ACCOUNT_NAME}/g; s|__AZURITE_STORAGE__|/storage|g" /app/Caddyfile.template > "/storage/Caddyfile" # Start Caddy in the background to handle HTTPS requests and route them to Azurite. caddy start --config "/storage/Caddyfile" # Use start not run, start does not block the shell process. HOST_ARGS=("--blobHost" "127.0.0.1" "--queueHost" "127.0.0.1" "--tableHost" "127.0.0.1") else HOST_ARGS=("--blobHost" "0.0.0.0" "--queueHost" "0.0.0.0" "--tableHost" "0.0.0.0") fi 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 "/storage" \ --key "/storage/${ACCOUNT_NAME}_key.pem" --cert "/storage/${ACCOUNT_NAME}_cert.pem" \ "${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"