Allow configuring services with multiple domains
This commit is contained in:
parent
533d343054
commit
7069c2fe20
3 changed files with 63 additions and 40 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/env fish
|
#!/bin/env fish
|
||||||
begin
|
begin
|
||||||
|
set -l name anki
|
||||||
set -l dir (status dirname)
|
set -l dir (status dirname)
|
||||||
set -l source "$dir/docker-compose.secrets.yml"
|
set -l source "$dir/docker-compose.secrets.yml"
|
||||||
source "$dir/../service.fish"
|
source "$dir/../service.fish"
|
||||||
|
@ -21,8 +22,12 @@ begin
|
||||||
configureDockerService $argv
|
configureDockerService $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
function getServiceConfigs
|
function getServiceServers -V name
|
||||||
printf "%s\0" anki anki "" /
|
printf "$name" ""
|
||||||
|
end
|
||||||
|
|
||||||
|
function getServiceLocations -V name
|
||||||
|
printf "%s\0" "$name" /
|
||||||
end
|
end
|
||||||
|
|
||||||
runInstaller --force $argv
|
runInstaller --force $argv
|
||||||
|
|
|
@ -40,35 +40,37 @@ begin
|
||||||
end
|
end
|
||||||
|
|
||||||
function installDockerService -V dir -V nginxRoot -V portPattern
|
function installDockerService -V dir -V nginxRoot -V portPattern
|
||||||
set -l services (getServiceConfigs $argv | string split0)
|
set -l config (getServiceSecretsConfig $argv)
|
||||||
|
set -l servers (getServiceServers $argv | string split0)
|
||||||
|
|
||||||
for i in (seq 1 4 (count $services))
|
for i in (seq 1 2 (count $servers))
|
||||||
set -l file (mktemp)
|
set -l locations (getServiceLocations $i $argv)
|
||||||
set -l config (getServiceSecretsConfig $argv)
|
|
||||||
set -l service $services[$i]
|
for j in (seq 1 4 (count $locations))
|
||||||
set -l port (random 49152 65535)
|
set -l file (mktemp)
|
||||||
set -l portKey (__getServicePortKey "$service")
|
set -l port (random 49152 65535)
|
||||||
set -l exposedPort
|
set -l service $locations[$j]
|
||||||
sudo mkdir -p (getServiceRoot $argv)
|
set -l portKey (__getServicePortKey "$service")
|
||||||
sudo mkdir -p "$nginxRoot"
|
set -l exposedPort
|
||||||
cp "$config" "$file"
|
sudo mkdir -p (getServiceRoot $argv)
|
||||||
set exposedPort (yq --raw-output "$portKey" "$file" | sed "s/$portPattern/\1$port\3/")
|
sudo mkdir -p "$nginxRoot"
|
||||||
PORT=$exposedPort yq -y "$portKey = env.PORT" "$file" | sudo tee "$config" >/dev/null
|
cp "$config" "$file"
|
||||||
|
|
||||||
|
set exposedPort (yq --raw-output "$portKey" "$file" | sed "s/$portPattern/\1$port\3/")
|
||||||
|
PORT=$exposedPort yq -y "$portKey = env.PORT" "$file" | sudo tee "$config" >/dev/null
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function configureDockerService -V portPattern
|
function configureDockerService -V portPattern
|
||||||
set -l services (getServiceConfigs $argv | string split0)
|
set -l config (getServiceSecretsConfig $argv)
|
||||||
|
set -l servers (getServiceServers $argv | string split0)
|
||||||
|
set -l nginxConfig (__getServiceNginxConfig $argv)
|
||||||
|
|
||||||
for i in (seq 1 4 (count $services))
|
for i in (seq 1 2 (count $servers))
|
||||||
set -l config (getServiceSecretsConfig $argv)
|
set -l domain $servers[(math $i + 1)]
|
||||||
set -l service $services[$i]
|
set -l subdomain $servers[(math $i)]
|
||||||
set -l subdomain $services[(math $i + 1)]
|
set -l locations (getServiceLocations $i $argv | string split0)
|
||||||
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" ]
|
if [ -z "$domain" ]
|
||||||
set domain (getMachineFQDN)
|
set domain (getMachineFQDN)
|
||||||
|
@ -78,19 +80,31 @@ begin
|
||||||
set domain "$subdomain.$domain"
|
set domain "$subdomain.$domain"
|
||||||
end
|
end
|
||||||
|
|
||||||
printf "%s\n" \
|
begin
|
||||||
"server {" \
|
printf "%s\n" \
|
||||||
"listen 80;" \
|
"server {" \
|
||||||
"server_name $domain;" \
|
"listen 80;" \
|
||||||
"location $location {" \
|
"server_name $domain;"
|
||||||
"proxy_pass http://127.0.0.1:$port;" \
|
|
||||||
'proxy_set_header Host $host;' \
|
for j in (seq 1 2 (count $locations))
|
||||||
'proxy_set_header X-Real-IP $remote_addr;' \
|
set -l service $locations[$j]
|
||||||
'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' \
|
set -l location $locations[(math $j + 1)]
|
||||||
'proxy_set_header X-Forwarded-Proto $scheme;' \
|
set -l portKey (__getServicePortKey "$service")
|
||||||
"}" \
|
set -l port (yq --raw-output "$portKey" "$config" | sed "s/$portPattern/\2/")
|
||||||
"}" | nix-shell -p crossplane --run "crossplane format /dev/stdin" | sudo tee "$nginxConfig" >/dev/null
|
|
||||||
end
|
printf "%s\n" \
|
||||||
|
"location $location {" \
|
||||||
|
"proxy_pass http://127.0.0.1:$port;" \
|
||||||
|
'proxy_set_header Host $host;' \
|
||||||
|
'proxy_set_header X-Real-IP $remote_addr;' \
|
||||||
|
'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' \
|
||||||
|
'proxy_set_header X-Forwarded-Proto $scheme;' \
|
||||||
|
"}"
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "}"
|
||||||
|
end
|
||||||
|
end | nix-shell -p crossplane --run "crossplane format /dev/stdin" | sudo tee "$nginxConfig" >/dev/null
|
||||||
|
|
||||||
sudo systemctl restart nginx
|
sudo systemctl restart nginx
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,9 +28,13 @@ begin
|
||||||
configureDockerService $argv
|
configureDockerService $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
function getServiceConfigs -V domain
|
function getServiceServers -V domain
|
||||||
|
printf "%s\0" "$domain" ""
|
||||||
|
end
|
||||||
|
|
||||||
|
function getServiceLocations
|
||||||
argparse -i "name=" -- $argv
|
argparse -i "name=" -- $argv
|
||||||
printf "%s\0" "$_flag_name" "$domain" "" /
|
printf "%s\0" "$_flag_name" /
|
||||||
end
|
end
|
||||||
|
|
||||||
function getBackupArgs
|
function getBackupArgs
|
||||||
|
|
Loading…
Reference in a new issue