From a3fa329f01778b2c254f0d3c45e608bd989e2f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Fr=C3=A9con?= Date: Mon, 21 May 2018 00:02:03 +0200 Subject: [PATCH 1/2] Support for env variables ending with _FILE --- run.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/run.sh b/run.sh index 20ee274d..e63dcc50 100755 --- a/run.sh +++ b/run.sh @@ -46,6 +46,26 @@ if [ ! -z ${GF_AWS_PROFILES+x} ]; then chmod 600 "$GF_PATHS_HOME/.aws/credentials" fi +# Convert all grafana variables which names ends with _FILE into the content of +# the file that they point at and using the name without the trailing _FILE. +# This can be used to carry in Docker secrets. +for VAR in $(env); do + if [ -n "$(echo $VAR | grep -E '^GF_' | grep -E '_FILE=')" ]; then + VAR_NAME_FILE=$(echo "$VAR" | sed -r "s/([^=]*)=.*/\1/g") + VAR_NAME=$(echo "$VAR_NAME_FILE" | sed -r "s/(.*)_FILE$/\1/g") + if [ "${!VAR_NAME}" ] && [ "${!VAR_NAME_FILE}" ]; then + echo >&2 "ERROR: Both $VAR_NAME and $VAR_NAME_FILE are set (but are exclusive)" + exit 1 + fi + if [ "${!VAR_NAME_FILE}" ]; then + echo "Getting secret $VAR_NAME from ${!VAR_NAME_FILE}" + VAL="$(< "${!VAR_NAME_FILE}")" + export "$VAR_NAME"="$VAL" + unset "$VAR_NAME_FILE" + fi + fi +done + export HOME="$GF_PATHS_HOME" if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then From 88c6d2fbcd64908458c7c7bb39a2c9278ced877c Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Thu, 31 May 2018 15:35:37 -0400 Subject: [PATCH 2/2] Simplify env _FILE script, tweak inline docs --- run.sh | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/run.sh b/run.sh index e63dcc50..44411f0f 100755 --- a/run.sh +++ b/run.sh @@ -46,24 +46,18 @@ if [ ! -z ${GF_AWS_PROFILES+x} ]; then chmod 600 "$GF_PATHS_HOME/.aws/credentials" fi -# Convert all grafana variables which names ends with _FILE into the content of -# the file that they point at and using the name without the trailing _FILE. +# Convert all environment variables with names ending in _FILE into the content of +# the file that they point at and use the name without the trailing _FILE. # This can be used to carry in Docker secrets. -for VAR in $(env); do - if [ -n "$(echo $VAR | grep -E '^GF_' | grep -E '_FILE=')" ]; then - VAR_NAME_FILE=$(echo "$VAR" | sed -r "s/([^=]*)=.*/\1/g") - VAR_NAME=$(echo "$VAR_NAME_FILE" | sed -r "s/(.*)_FILE$/\1/g") - if [ "${!VAR_NAME}" ] && [ "${!VAR_NAME_FILE}" ]; then - echo >&2 "ERROR: Both $VAR_NAME and $VAR_NAME_FILE are set (but are exclusive)" - exit 1 - fi - if [ "${!VAR_NAME_FILE}" ]; then - echo "Getting secret $VAR_NAME from ${!VAR_NAME_FILE}" - VAL="$(< "${!VAR_NAME_FILE}")" - export "$VAR_NAME"="$VAL" - unset "$VAR_NAME_FILE" - fi +for VAR_NAME in $(env | grep '^GF_[^=]\+_FILE=.\+' | sed -r "s/([^=]*)_FILE=.*/\1/g"); do + VAR_NAME_FILE="$VAR_NAME"_FILE + if [ "${!VAR_NAME}" ]; then + echo >&2 "ERROR: Both $VAR_NAME and $VAR_NAME_FILE are set (but are exclusive)" + exit 1 fi + echo "Getting secret $VAR_NAME from ${!VAR_NAME_FILE}" + export "$VAR_NAME"="$(< "${!VAR_NAME_FILE}")" + unset "$VAR_NAME_FILE" done export HOME="$GF_PATHS_HOME" @@ -85,4 +79,4 @@ exec grafana-server \ cfg:default.paths.data="$GF_PATHS_DATA" \ cfg:default.paths.logs="$GF_PATHS_LOGS" \ cfg:default.paths.plugins="$GF_PATHS_PLUGINS" \ - cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING" \ No newline at end of file + cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING"