diff --git a/.gitignore b/.gitignore index 4c52ea4..1d65957 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,8 @@ production.tfvars terraform.tfstate terraform.tfstate.backup -app \ No newline at end of file +app + +apps.config + +all-apps/lb/Caddyfile \ No newline at end of file diff --git a/Makefile b/Makefile index 991df38..9da0c82 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,10 @@ app/.dirstamp: all-apps/app.service all-apps/docker-compose.yaml $(wildcard all- rm -Rf app/ cp -a all-apps app && touch $@ -ignition.json: cl.yaml app/.dirstamp +all-apps/lb/Caddyfile: apps.config make-caddyfile.sh + ./make-caddyfile.sh > all-apps/lb/Caddyfile + +ignition.json: cl.yaml app/.dirstamp all-apps/lb/Caddyfile cat cl.yaml | sudo docker run --rm --volume /home/tjhintz/.ssh/id_rsa.pub:/pwd/ssh-keys --volume ${PWD}:/pwd --workdir /pwd -i quay.io/coreos/butane:latest -d /pwd > ignition.json plan: ignition.json diff --git a/all-apps/lb/Caddyfile b/all-apps/lb/Caddyfile deleted file mode 100644 index 60f2e03..0000000 --- a/all-apps/lb/Caddyfile +++ /dev/null @@ -1,17 +0,0 @@ -wg-easy1.nassella.cc { - reverse_proxy http://wg-easy:80 - - # tls internal - # x - # log -} - -nextcloud1.nassella.cc { - reverse_proxy http://nextcloud:80 - # tls internal -} - -root.nassella.cc { - reverse_proxy http://nginx:80 - # tls internal -} \ No newline at end of file diff --git a/apps.config.tmpl b/apps.config.tmpl new file mode 100644 index 0000000..3e44604 --- /dev/null +++ b/apps.config.tmpl @@ -0,0 +1,2 @@ +ROOT_DOMAIN=example.com +APP_CONFIGS="nextcloud,nextcloud wg-easy,wg-easy" \ No newline at end of file diff --git a/make-caddyfile.sh b/make-caddyfile.sh new file mode 100755 index 0000000..084866b --- /dev/null +++ b/make-caddyfile.sh @@ -0,0 +1,42 @@ +#!/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 + +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["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 + + +