Skip to content

Instantly share code, notes, and snippets.

@c-w
Last active April 12, 2024 04:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c-w/5de68791603855eb0559c585deaf42df to your computer and use it in GitHub Desktop.
Save c-w/5de68791603855eb0559c585deaf42df to your computer and use it in GitHub Desktop.
Docker entrypoint that sources dotenv file secrets
#!/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