Skip to content

Commit

Permalink
Allow using docker secrets for env variables (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Léo Colombaro <[email protected]>
  • Loading branch information
jhollowe and LeoColomb authored Jun 24, 2020
1 parent a8e13b5 commit e0b94b1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#!/bin/bash
set -euo pipefail

# 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
printf 'Both %s and %s are set (but are exclusive)' "$var" "$fileVar"
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}

file_env 'YOURLS_DB_HOST'
file_env 'YOURLS_DB_USER'
file_env 'YOURLS_DB_PASS'
file_env 'YOURLS_DB_NAME'
file_env 'YOURLS_DB_PREFIX'
file_env 'YOURLS_SITE'
file_env 'YOURLS_USER'
file_env 'YOURLS_PASS'

if [ ! -e /var/www/html/yourls-loader.php ]; then
tar cf - --one-file-system -C /usr/src/yourls . | tar xf -
chown -R www-data:www-data /var/www/html
Expand Down

0 comments on commit e0b94b1

Please sign in to comment.