From 8e5d144d9df0472374e8dfe89c1f64af838ed7d4 Mon Sep 17 00:00:00 2001 From: nscuro Date: Mon, 23 Oct 2023 22:06:46 +0200 Subject: [PATCH] Use `touch` instead of `mount` to check whether `config.json` is mounted Additionally, modify the `config.json` file in place when populating it from environment variables, instead of using a temporary file. The populated config will be logged by the entrypoint script. Fixes #60 Co-authored-by: Steffen Mueller <113037816+muellerst-hg@users.noreply.github.com> Signed-off-by: nscuro --- .../30-oidc-configuration.sh | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/docker/docker-entrypoint.d/30-oidc-configuration.sh b/docker/docker-entrypoint.d/30-oidc-configuration.sh index 24be92420..778eb7d2a 100755 --- a/docker/docker-entrypoint.d/30-oidc-configuration.sh +++ b/docker/docker-entrypoint.d/30-oidc-configuration.sh @@ -2,22 +2,27 @@ set -e -# 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" +entrypoint_log() { + if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then + echo "$@" + fi +} + +ME=$(basename $0) + +if ! touch ./static/config.json 2>/dev/null; then + entrypoint_log "$ME: info: 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 - | .API_WITH_CREDENTIALS = env.API_WITH_CREDENTIALS + CONFIG=$(jq '.API_BASE_URL = env.API_BASE_URL + | .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' \ - ./static/config.json > /tmp/config.json - - # Override default config file - mv -f /tmp/config.json ./static/config.json + ./static/config.json) + echo "${CONFIG}" > ./static/config.json + entrypoint_log "$ME: info: effective config: $(echo "${CONFIG}" | jq -c '.')" fi exec "$@"