fix: update start-azurite script to improve error handling and streamline container arguments
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
AZURITE_DIR="${AZURITE_DIR:-$(pwd)}"
|
||||
set -euo pipefail
|
||||
|
||||
AZURITE_DIR="${AZURITE_DIR:-}"
|
||||
CONTAINER_ARGS=()
|
||||
AZURITE_IMAGE="${AZURITE_IMAGE:-azurite:latest}"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-o|--oauth)
|
||||
--no-oauth)
|
||||
# OAuth support
|
||||
CONTAINER_ARGS+=("--oauth")
|
||||
CONTAINER_ARGS+=("--no-oauth")
|
||||
shift
|
||||
;;
|
||||
-d|--azurite-dir)
|
||||
@@ -27,10 +29,52 @@ while [[ $# -gt 0 ]]; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Check, if the AZURITE_DIR variable is set and is a valid directory
|
||||
if [[ -z "$AZURITE_DIR" || ! -d "$AZURITE_DIR" ]]; then
|
||||
echo "Error: AZURITE_DIR is not set or is not a valid directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check, if the accounts.env file exists in the AZURITE_DIR directory
|
||||
if [[ ! -f "$AZURITE_DIR/accounts.env" ]]; then
|
||||
echo "Error: accounts.env file not found in AZURITE_DIR directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "$AZURITE_DIR/accounts.env"
|
||||
if [[ -z "$AZURITE_ACCOUNTS" ]]; then
|
||||
echo "Error: AZURITE_ACCOUNTS variable is not set in accounts.env file." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ACCOUNT_NAME=$(echo "$AZURITE_ACCOUNTS" | cut -f 1 -d ';' | cut -f 1 -d ':')
|
||||
|
||||
# Check, if the certificate for the account exists.
|
||||
if [[ ! -f "$AZURITE_DIR/storage/${ACCOUNT_NAME}_cert.pem" ]] || [[ ! -f "$AZURITE_DIR/storage/${ACCOUNT_NAME}_key.pem" ]]; then
|
||||
echo "Error: Certificate or key for account ${ACCOUNT_NAME} not found in AZURITE_DIR directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v docker &> /dev/null; then
|
||||
docker run --rm -d --name azurite --env-file "$AZURITE_DIR/accounts.env" -p 443:443 -v "$AZURITE_DIR/storage":/storage "$AZURITE_IMAGE" "${CONTAINER_ARGS[@]}"
|
||||
docker run \
|
||||
--rm \
|
||||
-d \
|
||||
--name azurite \
|
||||
--env-file "$AZURITE_DIR/accounts.env" \
|
||||
-p 443:443 \
|
||||
-v "$AZURITE_DIR/storage":/storage \
|
||||
"$AZURITE_IMAGE" "${CONTAINER_ARGS[@]}"
|
||||
elif command -v container &> /dev/null; then
|
||||
container run -c 2 -m 512M --rm -d --name azurite --env-file "$AZURITE_DIR/accounts.env" -p 443:443 --mount type=bind,source="$AZURITE_DIR/storage",target=/storage "$AZURITE_IMAGE" "${CONTAINER_ARGS[@]}"
|
||||
container run \
|
||||
-c 2 \
|
||||
-m 512M \
|
||||
--rm \
|
||||
-d \
|
||||
--name azurite \
|
||||
--env-file "$AZURITE_DIR/accounts.env" \
|
||||
-p 443:443 \
|
||||
--mount type=bind,source="$AZURITE_DIR/storage",target=/storage \
|
||||
"$AZURITE_IMAGE" "${CONTAINER_ARGS[@]}"
|
||||
else
|
||||
echo "Neither supported container runtime found." >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user