Generate nginx
config using printf
This commit is contained in:
parent
07e759193c
commit
9396e489d7
5 changed files with 28 additions and 37 deletions
|
@ -1,12 +0,0 @@
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name anki.nuth.ch;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:1337;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,6 +4,10 @@ begin
|
||||||
set -l source "$dir/docker-compose.secrets.yml"
|
set -l source "$dir/docker-compose.secrets.yml"
|
||||||
source "$dir/../service.fish"
|
source "$dir/../service.fish"
|
||||||
|
|
||||||
|
function getServiceSubdomain
|
||||||
|
echo "anki"
|
||||||
|
end
|
||||||
|
|
||||||
function installSW -V dir -V source
|
function installSW -V dir -V source
|
||||||
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
|
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
|
||||||
set -l userKey ".services.anki.environment.SYNC_USER1"
|
set -l userKey ".services.anki.environment.SYNC_USER1"
|
||||||
|
@ -21,10 +25,6 @@ begin
|
||||||
configureDockerService $argv
|
configureDockerService $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
function getServiceNginxConfigSource -V dir
|
|
||||||
echo "$dir/anki.conf"
|
|
||||||
end
|
|
||||||
|
|
||||||
function getServiceConfigs
|
function getServiceConfigs
|
||||||
printf "%s\0" "anki" "/"
|
printf "%s\0" "anki" "/"
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,14 @@ begin
|
||||||
echo "$_flag_name"
|
echo "$_flag_name"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function getServiceDomain
|
||||||
|
echo "$(getServiceSubdomain $argv).nuth.ch"
|
||||||
|
end
|
||||||
|
|
||||||
|
function getServiceSubdomain
|
||||||
|
getServiceName $argv
|
||||||
|
end
|
||||||
|
|
||||||
function getServiceRoot -V root
|
function getServiceRoot -V root
|
||||||
echo "$root/$(getServiceName $argv)"
|
echo "$root/$(getServiceName $argv)"
|
||||||
end
|
end
|
||||||
|
@ -36,7 +44,6 @@ begin
|
||||||
|
|
||||||
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 services (getServiceConfigs $argv | string split0)
|
||||||
sudo cp (getServiceNginxConfigSource $argv) (__getServiceNginxConfig $argv)
|
|
||||||
|
|
||||||
for i in (seq 1 2 (count $services))
|
for i in (seq 1 2 (count $services))
|
||||||
set -l file (mktemp)
|
set -l file (mktemp)
|
||||||
|
@ -64,10 +71,18 @@ begin
|
||||||
set -l port (yq --raw-output "$portKey" "$config" | sed "s/$portPattern/\2/")
|
set -l port (yq --raw-output "$portKey" "$config" | sed "s/$portPattern/\2/")
|
||||||
set -l nginxConfig (__getServiceNginxConfig $argv)
|
set -l nginxConfig (__getServiceNginxConfig $argv)
|
||||||
|
|
||||||
cat "$nginxConfig" | sed \
|
printf "%s\n" \
|
||||||
-e "\;location $location {;,/}/{" \
|
"server {" \
|
||||||
-e "s/\(proxy_pass \)\(.\+:\)\?[[:digit:]]\+\(;\)/\1\2$port\3/;" \
|
"listen 80;" \
|
||||||
-e "}" | sudo tee "$nginxConfig" >/dev/null
|
"server_name $(getServiceDomain $argv);" \
|
||||||
|
"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;' \
|
||||||
|
"}" \
|
||||||
|
"}" | nix-shell -p crossplane --run "crossplane format /dev/stdin" | sudo tee "$nginxConfig" >/dev/null
|
||||||
end
|
end
|
||||||
|
|
||||||
sudo systemctl restart nginx
|
sudo systemctl restart nginx
|
||||||
|
|
|
@ -4,6 +4,10 @@ begin
|
||||||
set -l source "$dir/docker-compose.secrets.yml"
|
set -l source "$dir/docker-compose.secrets.yml"
|
||||||
source "$dir/../service.fish"
|
source "$dir/../service.fish"
|
||||||
|
|
||||||
|
function getServiceSubdomain
|
||||||
|
echo "passwords"
|
||||||
|
end
|
||||||
|
|
||||||
function installSW -V dir -V source
|
function installSW -V dir -V source
|
||||||
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
|
set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32")
|
||||||
set -l dbKey ".services.vaultwarden.environment.DATABASE_URL"
|
set -l dbKey ".services.vaultwarden.environment.DATABASE_URL"
|
||||||
|
@ -22,10 +26,6 @@ begin
|
||||||
configureDockerService $argv
|
configureDockerService $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
function getServiceNginxConfigSource -V dir
|
|
||||||
echo "$dir/vaultwarden.conf"
|
|
||||||
end
|
|
||||||
|
|
||||||
function getServiceConfigs
|
function getServiceConfigs
|
||||||
argparse -i "name=" -- $argv
|
argparse -i "name=" -- $argv
|
||||||
printf "%s\0" "$_flag_name" "/"
|
printf "%s\0" "$_flag_name" "/"
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name passwords.nuth.ch;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:1337;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue