You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
Bash
53 lines
1.2 KiB
Bash
#!/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
|
|
|
|
. apps.config
|
|
|
|
host_admin_password_encoded=`echo "$HOST_ADMIN_PASSWORD" | sudo 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["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 "}"
|
|
done
|
|
|
|
|
|
|