#!/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 'POSTGRES_PASSWORD'
file_env 'MENTOR_GOOGLE_CALENDAR'
file_env 'GOOGLE_API_KEY'

# Start node api
npm run bootstrap;
npm start;

#!/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 'POSTGRES_PASSWORD'
file_env 'MENTOR_GOOGLE_CALENDAR'
file_env 'GOOGLE_API_KEY'
file_env 'MAILGUN_DOMAIN_DEV'
file_env 'MAILGUN_SECRET_DEV'
file_env 'MAILGUN_DOMAIN'
file_env 'MAILGUN_SECRET'

# Start node api
npm run bootstrap;
npm start;

Add Mailgun Environment Variables to Entrypoint
Add Mailgun Environment Variables to Entrypoint