From 6be745a6f4843e81b92c5b26aa6fa6c7c9122cba Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Sun, 20 Sep 2026 16:53:28 -0500 Subject: [PATCH] chore: configurable deployment --- deploy/example.env | 2 + deploy/run.sh | 71 +++++++++++++++++++++++---------- deploy/template/launch-hub.sh | 5 ++- deploy/template/nginx.conf | 10 ++--- deploy/template/systemd.service | 2 +- run.sh | 2 +- 6 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 deploy/example.env diff --git a/deploy/example.env b/deploy/example.env new file mode 100644 index 0000000..e1f002a --- /dev/null +++ b/deploy/example.env @@ -0,0 +1,2 @@ +domain=hub.hordelab.com +install_path=/var/horde/hub/ \ No newline at end of file diff --git a/deploy/run.sh b/deploy/run.sh index 1b80530..c51e660 100644 --- a/deploy/run.sh +++ b/deploy/run.sh @@ -2,42 +2,71 @@ set -euo pipefail cd "$(dirname "$0")" -host="root@hub.hordelab.com" -remote_path="/var/horde/hub/" +if [ ! -f .env ]; then + echo ".env file not found. You can create one by copying the provided example:" + echo "cp $(dirname "$0")/example.env $(dirname "$0")/.env" + exit 1 +fi +source .env + +# Required: crash if not set in .env +: "${domain:?domain is not defined in .env}" +: "${install_path:?install_path is not defined in .env}" + +# Optional: fall back to defaults +: "${data_path:=$install_path/local-data}" +: "${launch_path:=$data_path/hub-launch.sh}" +: "${service_name:=horde-hub}" +: "${port:=17922}" +: "${remote:=$domain}" + +read_template() { + sed \ + -e "s/\$DOMAIN/$domain/g" \ + -e "s|\$INSTALL_PATH|$install_path|g" \ + -e "s|\$LAUNCH_PATH|$launch_path|g" \ + -e "s|\$DATA_PATH|$data_path|g" \ + -e "s/\$SERVICE_NAME/$service_name/g" \ + -e "s/\$PORT/$port/g" \ + template/$1 +} + +upload_template() { + read_template $1 | ssh $remote "cat > \"$2\"" +} run_nginx() { echo "Uploading nginx config file" - scp template/nginx.conf "$host:/etc/nginx/sites-enabled/hub.hordelab.com" - ssh "$host" -t " - nginx -s reload - + upload_template nginx.conf "/etc/nginx/sites-enabled/$domain" + ssh $remote -t " # full process is currently broken - #certbot --keep -d hub.hordelab.com + #certbot --keep -d $domain # uncomment if needed - #certbot certonly -d hub.hordelab.com + #certbot certonly -d $domain - #nginx -s reload + nginx -s reload " } run_service() { echo "Uploading Launcher and Service" - scp template/launch-hub.sh "$host:/var/horde/launch-hub.sh" - scp template/systemd.service "$host:/etc/systemd/system/horde-hub.service" - ssh "$host" -t " + upload_template launch-hub.sh $launch_path + upload_template systemd.service "/etc/systemd/system/$service_name.service" + + ssh $remote -t " systemctl daemon-reload - systemctl enable horde-hub.service - systemctl start horde-hub.service + systemctl enable $service_name.service + systemctl start $service_name.service " } run_update() { echo "Updating repository" - ssh "$host" -t " + ssh $remote -t " source ~/.nvm/nvm.sh #? - cd /var/horde/hub + cd $install_path git pull make install make web @@ -45,14 +74,14 @@ run_update() { } run_dist() { - echo "Uploading frontend/dist to $host:/var/frontend/dist" - ssh "$host" "rm -rf $remote_path/frontend/dist && mkdir $remote_path/frontend/dist" - scp -r ../frontend/dist "$host:$remote_path/frontend/" + echo "Uploading frontend/dist to $remote:$install_path/frontend/dist" + ssh $remote "rm -rf $install_path/frontend/dist && mkdir $install_path/frontend/dist" + scp -r ../frontend/dist $remote:$install_path/frontend/ } restart_service() { - echo "Restarting horde-hub.service" - ssh "$host" -t "systemctl restart horde-hub.service" + echo "Restarting $service_name.service" + ssh $remote -t "systemctl restart $service_name.service" } # Determine which stages to run diff --git a/deploy/template/launch-hub.sh b/deploy/template/launch-hub.sh index 4a17ad7..c4de0e6 100644 --- a/deploy/template/launch-hub.sh +++ b/deploy/template/launch-hub.sh @@ -1,8 +1,9 @@ +# Remove tracked keys lmao export OPENAI_API_KEY=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 export REPLICATE_API_KEY=r8_J1lnphqfZNUtK9CIh81SE4uHWWKJuvR3tr8S2 export OPENROUTER_API_KEY=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 -export HORDE_DATA_DIR=/var/horde/hub-data +export HORDE_DATA_DIR=$DATA_PATH echo Starting Horde Server -/var/horde/hub/.venv/bin/python3 /var/horde/hub/backend/src/app.py \ No newline at end of file +$INSTALL_PATH/.venv/bin/python3 $INSTALL_PATH/backend/src/app.py \ No newline at end of file diff --git a/deploy/template/nginx.conf b/deploy/template/nginx.conf index 7029ed2..339e31c 100644 --- a/deploy/template/nginx.conf +++ b/deploy/template/nginx.conf @@ -2,7 +2,7 @@ server { listen 80; listen [::]:80; - server_name hub.hordelab.com; + server_name $DOMAIN; return 301 https://$host$request_uri; } @@ -12,13 +12,13 @@ server { listen 443 ssl; listen [::]:443 ssl; - server_name hub.hordelab.com; + server_name $DOMAIN; - ssl_certificate /etc/letsencrypt/live/hub.hordelab.com/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/hub.hordelab.com/privkey.pem; + ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem; location / { - proxy_pass http://localhost:17922; + proxy_pass http://localhost:$PORT; proxy_http_version 1.1; # Websocket support diff --git a/deploy/template/systemd.service b/deploy/template/systemd.service index 4a9bfaa..1ca6aad 100644 --- a/deploy/template/systemd.service +++ b/deploy/template/systemd.service @@ -5,7 +5,7 @@ After=network.target [Service] Type=simple Restart=always -ExecStart=bash /var/horde/launch-hub.sh +ExecStart=bash $LAUNCH_PATH [Install] WantedBy=multi-user.target diff --git a/run.sh b/run.sh index 53f8e6b..0928329 100644 --- a/run.sh +++ b/run.sh @@ -57,7 +57,7 @@ case "$1" in ;; "deploy") - bash deploy/run.sh $@ + bash deploy/run.sh "${@:2}" ;; # Execute with custom home directory if it exists