Skip to content

Instantly share code, notes, and snippets.

@tschifftner
Created December 22, 2020 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschifftner/a5f9c5353c13ad57352091bb7939b6d7 to your computer and use it in GitHub Desktop.
Save tschifftner/a5f9c5353c13ad57352091bb7939b6d7 to your computer and use it in GitHub Desktop.
Support for env variables ending with _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.
# Source: https://github.com/grafana/grafana-docker/pull/166/files
for VAR_NAME in $(env | grep '^[^=]\+_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment