fix: update entrypoint.sh to source accounts from accounts.env and improve Caddy handling
This commit is contained in:
@@ -6,12 +6,18 @@ set -e
|
|||||||
. /app/cert-functions.sh
|
. /app/cert-functions.sh
|
||||||
|
|
||||||
# Setup default storage location, account name and accounts file path.
|
# 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
|
# Check, if the AZURITE_ACCOUNTS variable is set
|
||||||
if [[ -z "$AZURITE_ACCOUNTS" ]]; then
|
if [[ -z "$AZURITE_ACCOUNTS" ]]; then
|
||||||
# Generate a default account
|
if [[ -f "$AZURITE_STORAGE/accounts.env" ]]; then
|
||||||
export AZURITE_ACCOUNTS="devstoreaccount1:$(openssl rand -base64 32)"
|
set -a
|
||||||
|
source "$AZURITE_STORAGE/accounts.env"
|
||||||
|
set +a
|
||||||
|
else
|
||||||
|
# Generate a default account
|
||||||
|
export AZURITE_ACCOUNTS="devstoreaccount1:$(openssl rand -base64 32)"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Look up the account name from the AZURITE_ACCOUNTS variable, which is in the format "accountName:accountKey1:accountKey2;accountName2:accountKey1:accountKey2"
|
# 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 <<EOF >> /etc/hosts
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
OAUTH_ARGS=()
|
OAUTH_ARGS=()
|
||||||
|
NO_CADDY=
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
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.
|
# Ensure Caddy is disabled when using OAuth, as Azurite does not support OAuth behind a reverse proxy.
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--no-caddy)
|
||||||
|
NO_CADDY=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown argument: $1"
|
echo "Unknown argument: $1"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -45,20 +56,23 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Ensure certificates are generated before starting Azurite or Caddy.
|
# 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
|
echo "Error: Failed to create CA certificate and key." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
echo "Error: Failed to create server certificate and key." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate a Caddyfile configuration based on the account name and storage directory.
|
# 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")
|
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")
|
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.
|
# Start Azurite with the appropriate arguments based on the configuration.
|
||||||
exec node /app/azurite/src/azurite.js \
|
exec node /app/azurite/src/azurite.js \
|
||||||
--disableTelemetry \
|
--disableTelemetry \
|
||||||
--location "$AZURITE_DIR" \
|
--location "$AZURITE_STORAGE" \
|
||||||
--key "$AZURITE_DIR/${ACCOUNT_NAME}_key.pem" --cert "$AZURITE_DIR/${ACCOUNT_NAME}_cert.pem" \
|
--key "$AZURITE_STORAGE/${ACCOUNT_NAME}_key.pem" --cert "$AZURITE_STORAGE/${ACCOUNT_NAME}_cert.pem" \
|
||||||
"${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"
|
"${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"
|
||||||
|
|||||||
Reference in New Issue
Block a user