From c763ce67bb72e3873ab7cc1afdb467a92460e371 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 7 Nov 2024 03:31:48 +0100 Subject: [PATCH] Allow specifying domains per service --- .../docker/services/anki-sync/main.fish | 6 +---- .../Software/docker/services/service.fish | 26 ++++++++++--------- .../docker/services/vaultwarden/main.fish | 13 ++++------ 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/scripts/Common/Software/docker/services/anki-sync/main.fish b/scripts/Common/Software/docker/services/anki-sync/main.fish index 9c849081..c94174af 100755 --- a/scripts/Common/Software/docker/services/anki-sync/main.fish +++ b/scripts/Common/Software/docker/services/anki-sync/main.fish @@ -4,10 +4,6 @@ begin set -l source "$dir/docker-compose.secrets.yml" source "$dir/../service.fish" - function getServiceSubdomain - echo "anki" - end - function installSW -V dir -V source set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l userKey ".services.anki.environment.SYNC_USER1" @@ -26,7 +22,7 @@ begin end function getServiceConfigs - printf "%s\0" "anki" "/" + printf "%s\0" anki anki "" / end runInstaller --force $argv diff --git a/scripts/Common/Software/docker/services/service.fish b/scripts/Common/Software/docker/services/service.fish index f24d9c01..36ea5c11 100644 --- a/scripts/Common/Software/docker/services/service.fish +++ b/scripts/Common/Software/docker/services/service.fish @@ -17,14 +17,6 @@ begin getOSConfig fqdn end - function getServiceDomain - echo "$(getServiceSubdomain $argv).$(getMachineFQDN)" - end - - function getServiceSubdomain - getServiceName $argv - end - function getServiceRoot -V root echo "$root/$(getServiceName $argv)" end @@ -50,7 +42,7 @@ begin function installDockerService -V dir -V nginxRoot -V portPattern set -l services (getServiceConfigs $argv | string split0) - for i in (seq 1 2 (count $services)) + for i in (seq 1 4 (count $services)) set -l file (mktemp) set -l config (getServiceSecretsConfig $argv) set -l service $services[$i] @@ -68,18 +60,28 @@ begin function configureDockerService -V portPattern set -l services (getServiceConfigs $argv | string split0) - for i in (seq 1 2 (count $services)) + for i in (seq 1 4 (count $services)) set -l config (getServiceSecretsConfig $argv) set -l service $services[$i] - set -l location $services[(math $i + 1)] + set -l subdomain $services[(math $i + 1)] + set -l domain $services[(math $i + 2)] + set -l location $services[(math $i + 3)] set -l portKey (__getServicePortKey "$service") set -l port (yq --raw-output "$portKey" "$config" | sed "s/$portPattern/\2/") set -l nginxConfig (__getServiceNginxConfig $argv) + if [ -z "$domain" ] + set domain (getMachineFQDN) + end + + if [ -n "$subdomain" ] + set domain "$subdomain.$domain" + end + printf "%s\n" \ "server {" \ "listen 80;" \ - "server_name $(getServiceDomain $argv);" \ + "server_name $domain;" \ "location $location {" \ "proxy_pass http://127.0.0.1:$port;" \ 'proxy_set_header Host $host;' \ diff --git a/scripts/Common/Software/docker/services/vaultwarden/main.fish b/scripts/Common/Software/docker/services/vaultwarden/main.fish index 58fd2d9a..06121ad3 100644 --- a/scripts/Common/Software/docker/services/vaultwarden/main.fish +++ b/scripts/Common/Software/docker/services/vaultwarden/main.fish @@ -1,14 +1,11 @@ #!/bin/env fish begin set -l dir (status dirname) + set -l domain "passwords" set -l source "$dir/docker-compose.secrets.yml" source "$dir/../service.fish" - function getServiceSubdomain - echo "passwords" - end - - function installSW -V dir -V source + function installSW -V dir -V domain -V source set -l file "$dir/docker-compose.yml" set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l envKey ".services.vaultwarden.environment" @@ -16,7 +13,7 @@ begin set -l dbUrl (yq --raw-output "$dbKey" "$source" | sed "s/^\(.*:\/\/.*:\).*\(@.*\/.*\)\$/\1$pw\2/") initializeServiceInstallation $argv - URL="https://$(getServiceDomain $argv)" yq "$envKey.DOMAIN = env.URL" "$file" | \ + URL="https://$domain.$(getMachineFQDN)" yq "$envKey.DOMAIN = env.URL" "$file" | \ ADDRESS="noreply@$(getMachineFQDN)" yq -y "$envKey.SMTP_FROM = env.ADDRESS" | \ sudo tee "$(getServiceRoot $argv)/$(basename "$file")" >/dev/null @@ -31,9 +28,9 @@ begin configureDockerService $argv end - function getServiceConfigs + function getServiceConfigs -V domain argparse -i "name=" -- $argv - printf "%s\0" "$_flag_name" "/" + printf "%s\0" "$_flag_name" "$domain" "" / end function getBackupArgs