Initial working docker-templater+caddy version
This commit is contained in:
parent
ed71970153
commit
3544247fc0
5 changed files with 55 additions and 29 deletions
|
@ -4,9 +4,9 @@ DOCKER_SOCK_PATH="${DOCKER_SOCK_PATH:-/tmp/docker.sock}"
|
|||
DOCKER_CADDY_NAME="${DOCKER_CADDY_NAME:-proxy}"
|
||||
DOCKER_CADDY_PORT="${DOCKER_CADDY_PORT:-2020}"
|
||||
|
||||
WRAP_START='{\n admin :2020\n}\n'
|
||||
WRAP_START='{\n\tadmin :2020\n}\n'
|
||||
WRAP_END='\n'
|
||||
TEMPLATE='${LOCAL_WEB_HOST} {\n reverse_proxy ${LOCAL_IP}:$LOCAL_WEB_PORT\n}'
|
||||
TEMPLATE='${LOCAL_WEB_HOST} {\n\treverse_proxy ${LOCAL_IP}:$LOCAL_WEB_PORT\n}'
|
||||
SEPARATOR='\n'
|
||||
OUT='/config/Caddyfile'
|
||||
|
||||
|
@ -15,19 +15,18 @@ label_hook() {
|
|||
}
|
||||
|
||||
template_hook() {
|
||||
printf "%s" "${PARTIAL_RESULT}"
|
||||
if grep '^[^ ]\+ {\\n reverse_proxy \(?::\|[.0-9a-e]\)\+\:[0-9]\+\\n}$' <<< "${PARTIAL_RESULT}"
|
||||
if grep -q '^[^ ]\+ {\\n\\treverse_proxy \(?::\|[.0-9a-e]\)\+\:[0-9]\+\\n}$' <<< "${PARTIAL_RESULT}"
|
||||
then
|
||||
return 0;
|
||||
fi
|
||||
return 1;
|
||||
}
|
||||
|
||||
# finally_hook() {
|
||||
# if curl --silent -g "${DOCKER_CADDY_NAME}:${DOCKER_CADDY_PORT}/load"
|
||||
# then
|
||||
# printf "Updated Caddy Config"
|
||||
# else
|
||||
# printf "Failed to update Caddy Config"
|
||||
# fi
|
||||
# }
|
||||
finally_hook() {
|
||||
if curl --silent "${DOCKER_CADDY_NAME}:${DOCKER_CADDY_PORT}/load" -H "Content-Type: text/caddyfile" --data-binary "@${OUT}"
|
||||
then
|
||||
printf '%s | Updated Caddy Config\n' "$(get_date)"
|
||||
else
|
||||
printf '%s | Failed to update Caddy Config\n' "$(get_date)"
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@ set -e
|
|||
WRAP_START='[\n'
|
||||
if ${EXCLUDE_USERPASS}
|
||||
then
|
||||
TEMPLATE=' { type: "${LOCAL_DB_TYPE}", host: "${LOCAL_DB_HOST}", port: "${LOCAL_DB_PORT}" }'
|
||||
TEMPLATE=' { "type": "${LOCAL_DB_TYPE}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
|
||||
else
|
||||
TEMPLATE=' { type: "${LOCAL_DB_TYPE}", user: "${LOCAL_DB_USER}", password: "${LOCAL_DB_PASSWORD}", host: "${LOCAL_DB_HOST}", port: "${LOCAL_DB_PORT}" }'
|
||||
TEMPLATE=' { "type": "${LOCAL_DB_TYPE}", "user": "${LOCAL_DB_USER}", "password": "${LOCAL_DB_PASSWORD}", "host": "${LOCAL_DB_HOST}", "port": "${LOCAL_DB_PORT}" }'
|
||||
fi
|
||||
SEPARATOR=',\n'
|
||||
WRAP_END='\n]'
|
||||
OUT="/config/sqlproxy.json"
|
||||
|
||||
template_hook() {
|
||||
if grep -q 'type: "(?mysql|psql)".*host: ".+", port: "\d+"'
|
||||
if grep -q '"type": "(?mysql|psql)".*"host": ".+", port: "\d+"' <<< "${PARTIAL_RESULT}"
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue