From 89c06eb4b89b1a45ede531db450f8bc285544f5f Mon Sep 17 00:00:00 2001 From: Steffen Mueller <113037816+muellerst-hg@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:05:01 +0200 Subject: [PATCH 1/2] Improve test if static/config.json is writeable Fixes #60 Signed-off-by: Steffen Mueller <113037816+muellerst-hg@users.noreply.github.com> --- docker/docker-entrypoint.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 24be92420..f6dc780e6 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -2,9 +2,12 @@ set -e +CONFIG_FILE="./static/config.json" +TMP_FILE="/tmp/config.json" + # Check if config.json is mounted -if mount | grep '/static/config.json'; then - echo "config.json is mounted from host - ENV configuration will be ignored" +if ! touch $CONFIG_FILE 2>/dev/null; then + echo "can not modify config.json - ENV configuration will be ignored" else # Apply ENV vars to temporary config.json jq '.API_BASE_URL = env.API_BASE_URL @@ -14,10 +17,11 @@ else | .OIDC_SCOPE = env.OIDC_SCOPE | .OIDC_FLOW = env.OIDC_FLOW | .OIDC_LOGIN_BUTTON_TEXT = env.OIDC_LOGIN_BUTTON_TEXT' \ - ./static/config.json > /tmp/config.json + $CONFIG_FILE > $TMP_FILE # Override default config file - mv -f /tmp/config.json ./static/config.json + mv -f $TMP_FILE $CONFIG_FILE fi exec "$@" + From 73ebe9dc0bdfad7b9a2a588ed58761182f496d4a Mon Sep 17 00:00:00 2001 From: Steffen Mueller <113037816+muellerst-hg@users.noreply.github.com> Date: Tue, 13 Jun 2023 13:13:36 +0200 Subject: [PATCH 2/2] Introduce config.json template file Signed-off-by: Steffen Mueller <113037816+muellerst-hg@users.noreply.github.com> --- README.md | 2 +- docker/docker-entrypoint.sh | 18 +++++++----------- .../static/{config.json => config.tmpl.json} | 0 3 files changed, 8 insertions(+), 12 deletions(-) rename public/static/{config.json => config.tmpl.json} (100%) diff --git a/README.md b/README.md index d75f492a4..52a616acc 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ reflect the base URL of a Dependency-Track server. ![Deployment Options](https://raw.githubusercontent.com/DependencyTrack/frontend/master/docs/images/Frontend-Deployment.svg?sanitize=true) The front-end is deployed to a general purpose web server (e.g. NGINX or Apache). To configure the front-end -for this scenario, simply change the value of API_BASE_URL in static/config.json. +for this scenario, simply copy `static/config.tmpl.json` to `static/config.json` and change the value of API_BASE_URL in `static/config.json`. ```json { diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index f6dc780e6..b93c6104b 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -3,25 +3,21 @@ set -e CONFIG_FILE="./static/config.json" -TMP_FILE="/tmp/config.json" +TEMPLATE_FILE="./static/config.tmpl.json" -# Check if config.json is mounted -if ! touch $CONFIG_FILE 2>/dev/null; then - echo "can not modify config.json - ENV configuration will be ignored" +# Check if config.json exists +if test -f $CONFIG_FILE; then + echo "config.json already exists - ENV variables will be ignored" else - # Apply ENV vars to temporary config.json + echo "Creating config.json using ENV variables" jq '.API_BASE_URL = env.API_BASE_URL - | .API_WITH_CREDENTIALS = env.API_WITH_CREDENTIALS + | .API_WITH_CREDENTIALS = env.API_WITH_CREDENTIALS | .OIDC_ISSUER = env.OIDC_ISSUER | .OIDC_CLIENT_ID = env.OIDC_CLIENT_ID | .OIDC_SCOPE = env.OIDC_SCOPE | .OIDC_FLOW = env.OIDC_FLOW | .OIDC_LOGIN_BUTTON_TEXT = env.OIDC_LOGIN_BUTTON_TEXT' \ - $CONFIG_FILE > $TMP_FILE - - # Override default config file - mv -f $TMP_FILE $CONFIG_FILE + $TEMPLATE_FILE > $CONFIG_FILE fi exec "$@" - diff --git a/public/static/config.json b/public/static/config.tmpl.json similarity index 100% rename from public/static/config.json rename to public/static/config.tmpl.json