Compare commits
3 Commits
8813a4d5ed
...
c8ac9ddebf
| Author | SHA1 | Date | |
|---|---|---|---|
| c8ac9ddebf | |||
| ffdfc2697b | |||
| b698521720 |
@@ -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[@]}"
|
||||||
|
|||||||
27
run.sh
27
run.sh
@@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
AZURITE_DIR="${AZURITE_DIR:-./storage}"
|
|
||||||
CONTAINER_ARGS=()
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case "$1" in
|
|
||||||
-o|--oauth)
|
|
||||||
# OAuth support
|
|
||||||
CONTAINER_ARGS+=("--oauth")
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown argument: $1" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if command -v dockerd &> /dev/null; then
|
|
||||||
docker run --rm -d --name azurite --env-file accounts.env -p 443:443 -v "$AZURITE_DIR":/storage azurite:latest "${CONTAINER_ARGS[@]}"
|
|
||||||
elif command -v container &> /dev/null; then
|
|
||||||
container run --rm -d --name azurite --env-file accounts.env -p 443:443 --mount type=bind,source="$AZURITE_DIR",target=/storage azurite:latest "${CONTAINER_ARGS[@]}"
|
|
||||||
else
|
|
||||||
echo "Neither supported container runtime found." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
36
start-azurite
Executable file
36
start-azurite
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
AZURITE_DIR="${AZURITE_DIR:-$(pwd)}"
|
||||||
|
CONTAINER_ARGS=()
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-o|--oauth)
|
||||||
|
# OAuth support
|
||||||
|
CONTAINER_ARGS+=("--oauth")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-d|--azurite-dir)
|
||||||
|
if [[ -n "$2" && -d "$2" ]]; then
|
||||||
|
AZURITE_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
echo "Error: Selected directory does not exist." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument: $1" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if command -v dockerd &> /dev/null; then
|
||||||
|
docker run --rm -d --name azurite --env-file "$AZURITE_DIR/accounts.env" -p 443:443 -v "$AZURITE_DIR/storage":/storage azurite:latest "${CONTAINER_ARGS[@]}"
|
||||||
|
elif command -v container &> /dev/null; then
|
||||||
|
container run --rm -d --name azurite --env-file "$AZURITE_DIR/accounts.env" -p 443:443 --mount type=bind,source="$AZURITE_DIR/storage",target=/storage azurite:latest "${CONTAINER_ARGS[@]}"
|
||||||
|
else
|
||||||
|
echo "Neither supported container runtime found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user