feat: entrypoint
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
source deploy/docker/logging.sh
|
||||
|
||||
# usage: loadVariable VAR [DEFAULT]
|
||||
# ie: file_env 'DB_PASSWORD' 'example'
|
||||
# (will allow for "$DB_PASSWORD_FILE" to fill in the value of
|
||||
# "$DB_PASSWORD" from a file, especially for Docker's secrets feature)
|
||||
loadVariable() {
|
||||
local variable="$1"
|
||||
local variableFile="${variable}_FILE"
|
||||
local default="${2:-}"
|
||||
if [ "${!variable:-}" ] && [ "${!variableFile:-}" ]; then
|
||||
logError "Both $variable and $variableFile are set (but are exclusive)"
|
||||
fi
|
||||
local value="$default"
|
||||
if [ "${!variable:-}" ]; then
|
||||
value="${!variable}"
|
||||
elif [ "${!variableFile:-}" ]; then
|
||||
value="$(<"${!variableFile}")"
|
||||
fi
|
||||
export "$variable"="$value"
|
||||
unset "$variableFile"
|
||||
}
|
||||
|
||||
# loads various settings
|
||||
setupEnvironment() {
|
||||
loadVariable 'TIMEZONE' 'Etc/GMT'
|
||||
|
||||
# loadVariable 'MIGRATION_PATH' ''
|
||||
# # initialize values that might be stored in a file
|
||||
# loadVariable 'MYSQL_HOST'
|
||||
# loadVariable 'MYSQL_DATABASE' 'defaultDatabase'
|
||||
# loadVariable 'MYSQL_USER' 'defaultUser'
|
||||
# loadVariable 'MYSQL_PASSWORD'
|
||||
|
||||
# initialize values that might be stored in a file
|
||||
loadVariable 'TOKEN'
|
||||
loadVariable 'OWNER' 'default owner'
|
||||
}
|
||||
|
||||
# verify required environment.
|
||||
verifyEnvironment() {
|
||||
if [ -z "$TOKEN" ]; then
|
||||
logError $'Token is not completely filled\n\tYou need to specify $TOKEN'
|
||||
fi
|
||||
# if [ -z "$MYSQL_HOST" -o -z "$MYSQL_PASSWORD" ]; then
|
||||
# logError $'MYSQL databases credentials is not completely filled\n\tYou need to specify $MYSQL_HOST, $MYSQL_PASSWORD'
|
||||
# fi
|
||||
}
|
||||
|
||||
setupEnvironment
|
||||
verifyEnvironment
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# logging functions
|
||||
_log() {
|
||||
local type="$1"
|
||||
shift
|
||||
printf '%s [%s] [entrypoint]: %s\n' "$(date -R)" "$type" "$*"
|
||||
}
|
||||
|
||||
logNotice() {
|
||||
_log NOTICE "$@"
|
||||
}
|
||||
logWarning() {
|
||||
_log WARNING "$@" >&2
|
||||
}
|
||||
logError() {
|
||||
_log ERROR "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
startWaiting() {
|
||||
local type="NOTICE"
|
||||
printf '%s [%s] [entrypoint]: %s' "$(date -R)" "$type" "$*"
|
||||
}
|
||||
|
||||
waiting() {
|
||||
sleep 1
|
||||
printf '.'
|
||||
}
|
||||
|
||||
finishWaiting() {
|
||||
printf '\n'
|
||||
}
|
||||
Reference in New Issue
Block a user