Last active
April 12, 2024 04:22
-
-
Save c-w/5de68791603855eb0559c585deaf42df to your computer and use it in GitHub Desktop.
Docker entrypoint that sources dotenv file secrets
This file contains hidden or 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
#!/usr/bin/env sh | |
# This docker-entrypoint populates environment variables from docker secrets. | |
# The docker secrets are assumed to be files in dotenv syntax. The requested | |
# secrets should be declared in the environment variable DOTENV_SECRETS, with | |
# multiple secret names separated by a semi-colon. | |
if [ ! -d /run/secrets ]; then | |
exec "$@" | |
fi | |
if [ -z "${DOTENV_SECRETS}" ]; then | |
exec "$@" | |
fi | |
eval "$(find /run/secrets -maxdepth 1 -type f | grep "$(echo "${DOTENV_SECRETS}" | sed 's/;/\\|/g')" | xargs cat | grep -v '^#' | sed 's/^\([^=]\+\)=\(.*\)$/if [ -z "$\1" ]; then \1="\2"; export \1; fi/g')" | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment