From 738bbaad302b38dc4f3f0192f813b019157dda2d Mon Sep 17 00:00:00 2001 From: msukkari Date: Tue, 21 Jan 2025 12:20:55 -0800 Subject: [PATCH] add tenant mode support in docker container: --- Dockerfile | 2 ++ entrypoint.sh | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index afb7787e..9be035c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,8 @@ ARG SOURCEBOT_VERSION=unknown ENV SOURCEBOT_VERSION=$SOURCEBOT_VERSION RUN echo "Sourcebot Version: $SOURCEBOT_VERSION" +ENV SOURCEBOT_TENANT_MODE=single + # Valid values are: debug, info, warn, error ENV SOURCEBOT_LOG_LEVEL=info diff --git a/entrypoint.sh b/entrypoint.sh index e43c760c..ddbf6f09 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,18 +68,27 @@ fi echo "{\"version\": \"$SOURCEBOT_VERSION\", \"install_id\": \"$SOURCEBOT_INSTALL_ID\"}" > "$FIRST_RUN_FILE" -# Fallback to sample config if a config does not exist -if echo "$CONFIG_PATH" | grep -qE '^https?://'; then - if ! curl --output /dev/null --silent --head --fail "$CONFIG_PATH"; then - echo -e "\e[33m[Warning] Remote config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m" - CONFIG_PATH="./default-config.json" - fi -elif [ ! -f "$CONFIG_PATH" ]; then - echo -e "\e[33m[Warning] Config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m" - CONFIG_PATH="./default-config.json" +if [ ! -z "$SOURCEBOT_TENANT_MODE" ]; then + echo -e "\e[34m[Info] Sourcebot tenant mode: $SOURCEBOT_TENANT_MODE\e[0m" +else + echo -e "\e[31m[Error] SOURCEBOT_TENANT_MODE is not set.\e[0m" + exit 1 fi -echo -e "\e[34m[Info] Using config file at: '$CONFIG_PATH'.\e[0m" +# If we're in single tenant mode, fallback to sample config if a config does not exist +if [ "$SOURCEBOT_TENANT_MODE" = "single" ]; then + if echo "$CONFIG_PATH" | grep -qE '^https?://'; then + if ! curl --output /dev/null --silent --head --fail "$CONFIG_PATH"; then + echo -e "\e[33m[Warning] Remote config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m" + CONFIG_PATH="./default-config.json" + fi + elif [ ! -f "$CONFIG_PATH" ]; then + echo -e "\e[33m[Warning] Config file at '$CONFIG_PATH' not found. Falling back on sample config.\e[0m" + CONFIG_PATH="./default-config.json" + fi + + echo -e "\e[34m[Info] Using config file at: '$CONFIG_PATH'.\e[0m" +fi # Update NextJs public env variables w/o requiring a rebuild. # @see: https://phase.dev/blog/nextjs-public-runtime-variables/