Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Commit

Permalink
Simplify env _FILE script, tweak inline docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCech authored May 31, 2018
1 parent a3fa329 commit 88c6d2f
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING"

0 comments on commit 88c6d2f

Please sign in to comment.