Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using docker secrets for env variables #57

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
#!/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
mysql_error "Both $var and $fileVar are set (but are exclusive)"
jhollowe marked this conversation as resolved.
Show resolved Hide resolved
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_COOKIEKEY'
jhollowe marked this conversation as resolved.
Show resolved Hide resolved
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