Created
April 17, 2021 12:32
-
-
Save soloman1124/cdcf8e603f3064b2b49d614c6ed45a92 to your computer and use it in GitHub Desktop.
entrypoint.sh for docker secret
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 | |
| : ${ENV_SECRET_DIR:=/run/secrets} | |
| beginswith() { case $2 in "$1"*) true;; *) false;; esac; } | |
| dksec_expand() { | |
| for env_var in $(printenv) | |
| do | |
| value=$(echo $env_var | cut -d"=" -f2) | |
| if beginswith "dksec://" $value; | |
| then | |
| key=$(echo $env_var | cut -d"=" -f1) | |
| value=${value#"dksec://"} | |
| value=$(cat $ENV_SECRET_DIR/$value) | |
| export "$key"="$value" | |
| fi | |
| done | |
| } | |
| dksec_expand | |
| exec "$@" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://gist.github.com/bvis/b78c1e0841cfd2437f03e20c1ee059fe
Usage
Support loading environment vars from docker secrets with syntax like:
it will then lookup files in
/run/secrets/db_passwordDockerfile
it can be included in docker file with the following: