feat: entrypoint
This commit is contained in:
parent
d767706dec
commit
4c73ed54c5
52
deploy/docker/environment.sh
Normal file
52
deploy/docker/environment.sh
Normal file
@ -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
|
||||
|
||||
31
deploy/docker/logging.sh
Normal file
31
deploy/docker/logging.sh
Normal file
@ -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'
|
||||
}
|
||||
25
entrypoint.sh
Normal file
25
entrypoint.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
source deploy/docker/environment.sh
|
||||
source deploy/docker/logging.sh
|
||||
|
||||
IS_STARTED='/tmp/is-started'
|
||||
if [ ! -e $IS_STARTED ]; then
|
||||
logNotice 'Entrypoint script for golang-app started'
|
||||
|
||||
# logNotice 'Waiting to start MYSQL database...'
|
||||
# while ! mysql --protocol=TCP --host="$MYSQL_HOST" --user="$MYSQL_USER" --password="$MYSQL_PASSWORD" --execute="show databases;" --silent 1>/dev/null; do
|
||||
# sleep 1
|
||||
# done
|
||||
# logNotice 'Connected'
|
||||
|
||||
# if [ "$MIGRATION_PARAM" ]; then
|
||||
# logNotice 'Apply golang-app database migrations from ' $MIGRATION_PARAM
|
||||
# ./migrate -p $MIGRATION_PARAM up
|
||||
# fi
|
||||
|
||||
touch $IS_STARTED
|
||||
logNotice 'Project golang-app initialization complete. Ready for start up'
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Loading…
x
Reference in New Issue
Block a user