Created
December 22, 2020 09:39
-
-
Save tschifftner/a5f9c5353c13ad57352091bb7939b6d7 to your computer and use it in GitHub Desktop.
Support for env variables ending with _FILE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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