Skip to content

Commit

Permalink
Added file env support
Browse files Browse the repository at this point in the history
  • Loading branch information
7imbrook committed Apr 26, 2017
1 parent 1d2068a commit 651e4f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
#!/bin/bash

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}

# File envs
file_env 'GOOGLE_CLIENT_ID'
file_env 'GOOGLE_CLIENT_SECRET'
file_env 'SLACK_SECRET'
file_env 'PG_ENV_POSTGRES_PASSWORD'

echo $@;
if [ "$#" -ne 0 ]
then
Expand Down

0 comments on commit 651e4f8

Please sign in to comment.