83 lines
2.1 KiB
Bash
Executable File
83 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# this script generates the load-balancer
|
|
# config for the Caddy server.
|
|
|
|
# it depends on apps.config which should define:
|
|
# ROOT_DOMAIN - the root domain for all apps
|
|
# APP_CONFIGS - app-subdomain pairs, configured via a comma, like:
|
|
# app1,subdomain1 app2,subdomain2 app3,subdomain3
|
|
# full example:
|
|
# ROOT_DOMAIN=nassella.cc
|
|
# APP_CONFIGS="app1,subdomain1 app2,subdomain2 app3,subdomain3"
|
|
|
|
set -e
|
|
|
|
. $1 # source the apps.config file with then env vars
|
|
|
|
host_admin_password_encoded=`echo "$HOST_ADMIN_PASSWORD" | docker run --rm -i caddy:2 caddy hash-password`
|
|
|
|
|
|
read -r -a APP_CONFIGS <<< "$APP_CONFIGS"
|
|
APP_CONFIGS+=('lb,root')
|
|
|
|
|
|
declare -A bodys
|
|
bodys["nextcloud"]=" reverse_proxy http://nextcloud:80"
|
|
bodys["wg-easy"]=" reverse_proxy http://wg-easy:80"
|
|
bodys["ghost"]=" reverse_proxy http://ghost:2368"
|
|
bodys["nassella"]=$(cat <<EOF
|
|
route {
|
|
@authelia path /authelia /authelia/*
|
|
handle @authelia {
|
|
reverse_proxy nassella_authelia:9091
|
|
}
|
|
|
|
handle /unsecured/* {
|
|
reverse_proxy http://nassella:8080
|
|
}
|
|
|
|
forward_auth nassella_authelia:9091 {
|
|
uri /api/authz/forward-auth
|
|
copy_headers Remote-User Remote-Groups Remote-Email Remote-Name
|
|
}
|
|
|
|
reverse_proxy http://nassella:8080
|
|
}
|
|
EOF
|
|
)
|
|
bodys["dozzle"]=$(cat <<EOF
|
|
basic_auth {
|
|
$HOST_ADMIN_USER $host_admin_password_encoded
|
|
}
|
|
reverse_proxy http://dozzle:8080
|
|
EOF
|
|
)
|
|
bodys["lb"]=" reverse_proxy http://nginx:80"
|
|
|
|
for config_string in ${APP_CONFIGS[@]}; do
|
|
IFS=','
|
|
read -r -a config <<< "$config_string"
|
|
|
|
app=${config[0]}
|
|
subdomain=${config[1]}
|
|
body=${bodys[$app]}
|
|
fulldomain="$subdomain.$ROOT_DOMAIN"
|
|
|
|
echo "$fulldomain {"
|
|
echo $body
|
|
echo "}"
|
|
|
|
# this is a hack specifically for nassella
|
|
# because lldap should be on a separate domain
|
|
# for security but this was not designed for one app
|
|
# to map to multiple caddy blocks
|
|
# currently this is hardcoded to prefix the nassella
|
|
# domain with 'lldap'
|
|
if [ "$app" = "nassella" ]; then
|
|
echo "lldap.$subdomain.$ROOT_DOMAIN {"
|
|
echo " reverse_proxy nassella_lldap:17170"
|
|
echo "}"
|
|
fi
|
|
done
|