refactor: remove unused certificate generation functions and streamline entrypoint.sh
This commit is contained in:
@@ -1,35 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
# Include certificate generation functions.
|
|
||||||
. /app/cert-functions.sh
|
|
||||||
|
|
||||||
function make_account_cert() {
|
|
||||||
local CERT_DIR="$1"
|
|
||||||
local ACCOUNT_NAME="${2:-devstoreaccount1}"
|
|
||||||
# -addext "subjectAltName=DNS:${ACCOUNT_NAME}.blob.core.windows.net,DNS:${ACCOUNT_NAME}.queue.core.windows.net,DNS:${ACCOUNT_NAME}.table.core.windows.net,DNS:${ACCOUNT_NAME}.blob.localhost,DNS:${ACCOUNT_NAME}.queue.localhost,DNS:${ACCOUNT_NAME}.table.localhost,DNS:localhost,IP:127.0.0.1"
|
|
||||||
|
|
||||||
make_server_cert "$CERT_DIR" "${ACCOUNT_NAME}.blob.core.windows.net" \
|
|
||||||
"${ACCOUNT_NAME}.queue.core.windows.net" \
|
|
||||||
"${ACCOUNT_NAME}.table.core.windows.net" \
|
|
||||||
"${ACCOUNT_NAME}.blob.localhost" \
|
|
||||||
"${ACCOUNT_NAME}.queue.localhost" \
|
|
||||||
"${ACCOUNT_NAME}.table.localhost" \
|
|
||||||
"localhost" \
|
|
||||||
"127.0.0.1"
|
|
||||||
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# Setup default storage location, account name and accounts file path.
|
|
||||||
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
|
||||||
if [[ -f "$AZURITE_STORAGE/accounts.env" ]]; then
|
if [[ -f "/storage/accounts.env" ]]; then
|
||||||
set -a
|
set -a
|
||||||
source "$AZURITE_STORAGE/accounts.env"
|
source "/storage/accounts.env"
|
||||||
set +a
|
set +a
|
||||||
else
|
else
|
||||||
# Generate a default account
|
# Generate a default account
|
||||||
@@ -40,25 +17,13 @@ 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"
|
||||||
ACCOUNT_NAME=$(echo "$AZURITE_ACCOUNTS" | cut -f 1 -d ';' | cut -f 1 -d ':')
|
ACCOUNT_NAME=$(echo "$AZURITE_ACCOUNTS" | cut -f 1 -d ';' | cut -f 1 -d ':')
|
||||||
|
|
||||||
# Ensure /etc/hosts contains an entry the Azure endpoint names,
|
OAUTH_ARGS=("--oauth" "basic")
|
||||||
# so Caddy can route requests to the correct service based on the hostname.
|
|
||||||
if grep -q "${ACCOUNT_NAME}" /etc/hosts; then
|
|
||||||
cp -a /etc/hosts /etc/hosts.bak && sed -E "/${ACCOUNT_NAME}/d" /etc/hosts > /etc/hosts
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat <<EOF >> /etc/hosts
|
|
||||||
|
|
||||||
127.0.0.1 ${ACCOUNT_NAME}.blob.core.windows.net ${ACCOUNT_NAME}.queue.core.windows.net ${ACCOUNT_NAME}.table.core.windows.net ${ACCOUNT_NAME}.blob.localhost ${ACCOUNT_NAME}.queue.localhost ${ACCOUNT_NAME}.table.localhost
|
|
||||||
EOF
|
|
||||||
|
|
||||||
OAUTH_ARGS=()
|
|
||||||
NO_CADDY=
|
NO_CADDY=
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--oauth)
|
--no-oauth)
|
||||||
OAUTH_ARGS=("--oauth" "basic")
|
OAUTH_ARGS=()
|
||||||
# Ensure Caddy is disabled when using OAuth, as Azurite does not support OAuth behind a reverse proxy.
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--no-caddy)
|
--no-caddy)
|
||||||
@@ -72,22 +37,11 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Ensure certificates are generated before starting Azurite or Caddy.
|
|
||||||
if ! make_ca "$AZURITE_STORAGE" "Azurite CA $(date +%Y.%m)"; then
|
|
||||||
echo "Error: Failed to create CA certificate and key." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! make_account_cert "$AZURITE_STORAGE" "$ACCOUNT_NAME"; then
|
|
||||||
echo "Error: Failed to create server certificate and key." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z "$NO_CADDY" ]]; then
|
if [[ -z "$NO_CADDY" ]]; then
|
||||||
# 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_STORAGE__|${AZURITE_STORAGE}|g" /app/Caddyfile.example > "$AZURITE_STORAGE/Caddyfile"
|
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.
|
# 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.
|
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")
|
HOST_ARGS=("--blobHost" "127.0.0.1" "--queueHost" "127.0.0.1" "--tableHost" "127.0.0.1")
|
||||||
else
|
else
|
||||||
HOST_ARGS=("--blobHost" "0.0.0.0" "--queueHost" "0.0.0.0" "--tableHost" "0.0.0.0")
|
HOST_ARGS=("--blobHost" "0.0.0.0" "--queueHost" "0.0.0.0" "--tableHost" "0.0.0.0")
|
||||||
@@ -98,6 +52,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_STORAGE" \
|
--location "/storage" \
|
||||||
--key "$AZURITE_STORAGE/${ACCOUNT_NAME}_key.pem" --cert "$AZURITE_STORAGE/${ACCOUNT_NAME}_cert.pem" \
|
--key "/storage/${ACCOUNT_NAME}_key.pem" --cert "/storage/${ACCOUNT_NAME}_cert.pem" \
|
||||||
"${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"
|
"${HOST_ARGS[@]}" "${PORT_ARGS[@]}" "${OAUTH_ARGS[@]}"
|
||||||
|
|||||||
Reference in New Issue
Block a user