Move Rails secrets into Docker secrets

This commit is contained in:
2023-03-14 15:31:55 -04:00
parent 949f952ae4
commit bb35b39ea9
4 changed files with 50 additions and 5 deletions
+25 -2
View File
@@ -1,10 +1,33 @@
#! /bin/sh
#!/usr/bin/env bash
file_env() {
# 3wc: Load $VAR_FILE into $VAR - useful for secrets. See
# https://medium.com/@adrian.gheorghe.dev/using-docker-secrets-in-your-environment-variables-7a0609659aab
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_env "DEVISE_SECRET"
file_env "SECRET_COOKIE_TOKEN"
if test ! -f /loomio/storage/migrations_ran; then
echo "first deploy, running migrations..."
rake db:setup
touch /loomio/storage/migrations_ran
fi
echo "starting loomio!"
/loomio/docker_start.sh