64 lines
2.2 KiB
Bash
64 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
# Check, if the AZURITE_ACCOUNTS variable is set
|
|
if [[ -z "$AZURITE_ACCOUNTS" ]]; then
|
|
if [[ -f "/storage/accounts.env" ]]; then
|
|
set -a
|
|
source "/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 ':')
|
|
|
|
# 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[@]}"
|