From 2fbe5307daacb5599703cc29489498c89d671167 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 May 2025 19:36:33 +1200 Subject: [PATCH] Fixing --- remote_host_autosetup/host_autosetup.sh | 2 +- .../simple-object-storage/example/service.env | 5 +---- .../example/sos_config.json | 8 ++++++++ templates/simple-object-storage/ports.sh | 15 ++++++++++++++- templates/simple-object-storage/start.sh | 18 +++--------------- 5 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 templates/simple-object-storage/example/sos_config.json diff --git a/remote_host_autosetup/host_autosetup.sh b/remote_host_autosetup/host_autosetup.sh index 06197e7..54459ba 100755 --- a/remote_host_autosetup/host_autosetup.sh +++ b/remote_host_autosetup/host_autosetup.sh @@ -27,7 +27,7 @@ else fi # check if curl, wget, bash installed, and install if not -PREREQUISITES=("curl" "wget") +PREREQUISITES=("curl" "wget" "jq") # check if all prerequisites are installed ALLINSTALLED=true diff --git a/templates/simple-object-storage/example/service.env b/templates/simple-object-storage/example/service.env index 229c30f..dd27f69 100644 --- a/templates/simple-object-storage/example/service.env +++ b/templates/simple-object-storage/example/service.env @@ -1,7 +1,4 @@ -HOST_PORT=8123 +# note the port and write tokens are not set here, they are set in the sos_config.json file. CONTAINER_NAME="simple-object-storage" - VOLUME_NAME="simple-object-storage" - -WRITE_TOKENS="fizzle1,fizzle2,fizzle3" diff --git a/templates/simple-object-storage/example/sos_config.json b/templates/simple-object-storage/example/sos_config.json new file mode 100644 index 0000000..42d55d7 --- /dev/null +++ b/templates/simple-object-storage/example/sos_config.json @@ -0,0 +1,8 @@ +{ + "write_tokens": [ + "fizzle1", + "fizzle2", + "fizzle3" + ], + "port": 8123 +} diff --git a/templates/simple-object-storage/ports.sh b/templates/simple-object-storage/ports.sh index e88f668..8250a3c 100644 --- a/templates/simple-object-storage/ports.sh +++ b/templates/simple-object-storage/ports.sh @@ -10,4 +10,17 @@ source "$(dirname "$0")/_common.sh" # Required environment variables # check_required_env_vars "HOST_PORT" -echo $HOST_PORT +# check if jq is installed +if ! command -v jq &> /dev/null; then + die "jq could not be found, please install it" +fi + +# check if sos_config.json exists +if [ ! -f "${CONFIG_PATH}/sos_config.json" ]; then + die "sos_config.json does not exist" +fi + +# extract port from sos_config.json +PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json") +echo $PORT + diff --git a/templates/simple-object-storage/start.sh b/templates/simple-object-storage/start.sh index e1129d3..9f5df67 100644 --- a/templates/simple-object-storage/start.sh +++ b/templates/simple-object-storage/start.sh @@ -6,32 +6,20 @@ # It is called with the path to the server specific env file as an argument. source "$(dirname "$0")/_common.sh" -check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "VOLUME_NAME" "WRITE_TOKENS" +check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "VOLUME_NAME" "WRITE_TOKENS" "CONFIG_PATH" # check volume exists. if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then die "Docker volume ${VOLUME_NAME} does not exist" fi -# heredoc for config file. Have to use double quotes to substitute variables. -docker run --rm -v ${VOLUME_NAME}:/data debian bash -c "\ -cat < /data/sos_config.json -{ - \"write_tokens\": [ - ${WRITE_TOKENS} - ], - \"object_store_path\": \"/data/storage\", - \"host\": \"0.0.0.0\", - \"port\": ${HOST_PORT} -} -EOF -" DOCKER_RUN_CMD="docker run -d \ --restart unless-stopped \ --name ${CONTAINER_NAME} \ -p ${HOST_PORT}:80 \ - -v ${VOLUME_NAME}:/data \ + -v ${VOLUME_NAME}:/data/storage \ + -v ${CONFIG_PATH}/sos_config.json:/data/sos_config.json:ro \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}"