From bb1fb2f16df253977fd97e918f8c42a9667ec46b Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Mon, 28 Sep 2026 10:24:10 -0600 Subject: [PATCH] expose jellyfin through edge --- bootstrap/edge/main.tf | 18 +++++- bootstrap/edge/templates/default.conf.tftpl | 66 ++++++++++++++++++++- bootstrap/edge/variables.tf | 10 ++++ homelab.yml | 5 ++ infra/heimdall/homepage/services.yaml | 8 +-- infra/heimdall/links.json | 14 ++--- lib/jeannie/env.sh | 4 ++ lib/jeannie/pipeline.sh | 8 +++ scripts/generate-heimdall-links | 1 + 9 files changed, 120 insertions(+), 14 deletions(-) diff --git a/bootstrap/edge/main.tf b/bootstrap/edge/main.tf index 97eb7bf..8160f13 100644 --- a/bootstrap/edge/main.tf +++ b/bootstrap/edge/main.tf @@ -14,11 +14,13 @@ locals { crowdsec_whitelist = templatefile("${path.module}/templates/crowdsec-homelab-whitelist.yaml.tftpl", {}) heimdall_server_name = "heimdall.${var.server_name}" homepage_server_name = "homepage.${var.server_name}" + jellyfin_server_name = "jellyfin.${var.server_name}" heimdall_backend_host = var.heimdall_backend_host != "" ? var.heimdall_backend_host : var.gitea_backend_host homepage_backend_host = var.homepage_backend_host != "" ? var.homepage_backend_host : var.gitea_backend_host - server_names = distinct(concat([var.server_name, local.heimdall_server_name], var.additional_server_names)) + jellyfin_backend_host = var.jellyfin_backend_host != "" ? var.jellyfin_backend_host : var.gitea_backend_host + server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.jellyfin_server_name], var.additional_server_names)) matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : [] - main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name], name) && !contains(local.matrix_server_names, name)] + main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.jellyfin_server_name], name) && !contains(local.matrix_server_names, name)] default_conf = templatefile("${path.module}/templates/default.conf.tftpl", { server_name = var.server_name server_names = join(" ", local.server_names) @@ -34,6 +36,9 @@ locals { homepage_server_name = local.homepage_server_name homepage_backend_host = local.homepage_backend_host homepage_backend_port = tostring(var.homepage_backend_port) + jellyfin_server_name = local.jellyfin_server_name + jellyfin_backend_host = local.jellyfin_backend_host + jellyfin_backend_port = tostring(var.jellyfin_backend_port) }) default_vcl = templatefile("${path.module}/templates/default.vcl.tftpl", { backend_host = var.backend_host @@ -83,6 +88,8 @@ resource "null_resource" "edge_services" { gitea_backend_port = tostring(var.gitea_backend_port) heimdall_host = local.heimdall_backend_host heimdall_port = tostring(var.heimdall_backend_port) + jellyfin_host = local.jellyfin_backend_host + jellyfin_port = tostring(var.jellyfin_backend_port) enable_letsencrypt = tostring(var.enable_letsencrypt) letsencrypt_email = var.letsencrypt_email letsencrypt_staging = tostring(var.letsencrypt_staging) @@ -160,6 +167,8 @@ gitea_backend_host="${self.triggers.gitea_backend_host}" gitea_backend_port="${self.triggers.gitea_backend_port}" heimdall_host="${self.triggers.heimdall_host}" heimdall_port="${self.triggers.heimdall_port}" +jellyfin_host="${self.triggers.jellyfin_host}" +jellyfin_port="${self.triggers.jellyfin_port}" enable_letsencrypt="${self.triggers.enable_letsencrypt}" letsencrypt_email="${self.triggers.letsencrypt_email}" letsencrypt_staging="${self.triggers.letsencrypt_staging}" @@ -196,6 +205,11 @@ if ! curl -sS --connect-timeout 10 "http://$heimdall_host:$heimdall_port/" >/dev echo "Run ./jeannie deploy-heimdall on the Debian host if the service is missing." >&2 fi +if ! curl -sS --connect-timeout 10 "http://$jellyfin_host:$jellyfin_port/" >/dev/null; then + echo "Warning: cannot reach Jellyfin backend http://$jellyfin_host:$jellyfin_port/ from the edge host." >&2 + echo "Check the Debian Jellyfin container and published port before testing the public hostname." >&2 +fi + if ! command -v docker >/dev/null 2>&1; then if [ "$install_docker" = "true" ]; then curl -fsSL https://get.docker.com | sudo sh diff --git a/bootstrap/edge/templates/default.conf.tftpl b/bootstrap/edge/templates/default.conf.tftpl index 7cc433a..332e05a 100644 --- a/bootstrap/edge/templates/default.conf.tftpl +++ b/bootstrap/edge/templates/default.conf.tftpl @@ -3,6 +3,11 @@ map $request_uri $blocked_uris { ~*(/\.env|/\.git|/\.aws|/wp-admin) 1; } +map $http_upgrade $connection_upgrade { + default upgrade; + '' ""; +} + access_log /var/log/nginx/crowdsec-access.log; error_log /var/log/nginx/crowdsec-error.log warn; @@ -29,6 +34,11 @@ upstream homepage_backend { keepalive 8; } +upstream jellyfin_backend { + server ${jellyfin_backend_host}:${jellyfin_backend_port}; + keepalive 8; +} + set_real_ip_from 173.245.48.0/20; set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; @@ -63,7 +73,7 @@ server { server { listen 80; - server_name ${heimdall_server_name} ${homepage_server_name}; + server_name ${heimdall_server_name} ${homepage_server_name} ${jellyfin_server_name}; location ^~ /.well-known/acme-challenge/ { root /var/www/certbot; @@ -76,6 +86,60 @@ server { } } +server { + listen 443 ssl; + http2 on; + server_name ${jellyfin_server_name}; + + ssl_certificate /etc/nginx/certs/current.crt; + ssl_certificate_key /etc/nginx/certs/current.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_session_cache shared:homelab_ssl:10m; + ssl_session_timeout 1d; + + keepalive_timeout 65s; + keepalive_requests 1000; + + if ($blocked_uris) { return 403; } + + add_header X-Frame-Options SAMEORIGIN; + add_header X-XSS-Protection "1; mode=block"; + add_header X-Content-Type-Options nosniff; + add_header Referrer-Policy "strict-origin-when-cross-origin"; + add_header Permissions-Policy "geolocation=(), microphone=()"; + + gzip on; + gzip_comp_level 2; + gzip_min_length 1000; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + location = /edge-health { + access_log off; + return 204; + } + + location / { + limit_req zone=one burst=20 nodelay; + client_max_body_size 1024m; + + proxy_pass http://jellyfin_backend; + proxy_http_version 1.1; + proxy_buffering off; + proxy_request_buffering off; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + 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 https; + proxy_set_header CF-Connecting-IP $http_cf_connecting_ip; + add_header Cache-Control "no-store"; + } +} + server { listen 443 ssl; http2 on; diff --git a/bootstrap/edge/variables.tf b/bootstrap/edge/variables.tf index ed9ddef..ed09015 100644 --- a/bootstrap/edge/variables.tf +++ b/bootstrap/edge/variables.tf @@ -113,6 +113,16 @@ variable "homepage_backend_port" { default = 8083 } +variable "jellyfin_backend_host" { + type = string + default = "" +} + +variable "jellyfin_backend_port" { + type = number + default = 8096 +} + # Matrix (isolated vhost + its own cert; does NOT touch shared current.crt) variable "matrix_enabled" { type = bool diff --git a/homelab.yml b/homelab.yml index 356bd80..7492d4d 100644 --- a/homelab.yml +++ b/homelab.yml @@ -13,6 +13,7 @@ domain: - demos.lab2025.duckdns.org - heimdall.lab2025.duckdns.org - homepage.lab2025.duckdns.org + - jellyfin.lab2025.duckdns.org - matrix.lab2025.duckdns.org - element.lab2025.duckdns.org - grafana.lab2025.duckdns.org @@ -85,6 +86,10 @@ services: install_dir: /data/homelab-heimdall http_port: 8083 public_url: https://homepage.lab2025.duckdns.org/ + jellyfin: + host: debian + http_port: 8096 + public_url: https://jellyfin.lab2025.duckdns.org/ gitops_mirror: host: debian path: /home/jv/git-server/my-homelab-configs.git diff --git a/infra/heimdall/homepage/services.yaml b/infra/heimdall/homepage/services.yaml index 3050c4c..4ef219d 100644 --- a/infra/heimdall/homepage/services.yaml +++ b/infra/heimdall/homepage/services.yaml @@ -92,6 +92,10 @@ ping: "pimox-worker-02" - Media: + - Jellyfin: + href: "https://jellyfin.lab2025.duckdns.org/" + description: "Media streaming server" + icon: "jellyfin.png" - Prowlarr: href: "http://192.168.100.73:9696/" description: "Indexer management for the media automation stack" @@ -124,10 +128,6 @@ href: "http://192.168.100.73:8191/" description: "Browser challenge solver service for ARR automation" icon: "mdi-cloud-refresh" - - Jellyfin: - href: "http://192.168.100.73:8096/" - description: "Media streaming server" - icon: "jellyfin.png" - Communication: - Matrix: diff --git a/infra/heimdall/links.json b/infra/heimdall/links.json index 989fb20..a6f9544 100644 --- a/infra/heimdall/links.json +++ b/infra/heimdall/links.json @@ -27,6 +27,13 @@ "colour": "#0284c7", "class": "Homepage" }, + { + "title": "Jellyfin", + "url": "https://jellyfin.lab2025.duckdns.org/", + "description": "Media streaming server", + "colour": "#7c3aed", + "class": "Jellyfin" + }, { "title": "Matrix", "url": "https://matrix.lab2025.duckdns.org/", @@ -187,12 +194,5 @@ "description": "Browser challenge solver service for ARR automation", "colour": "#64748b", "class": "FlareSolverr" - }, - { - "title": "Jellyfin", - "url": "http://192.168.100.73:8096/", - "description": "Media streaming server", - "colour": "#7c3aed", - "class": "Jellyfin" } ] diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index 2f7b2b9..bb49a76 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -49,6 +49,8 @@ mapping = { "services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL", "services.homepage.http_port": "LAB_HOMEPAGE_HTTP_PORT", "services.homepage.public_url": "LAB_HOMEPAGE_PUBLIC_URL", + "services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT", + "services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL", "services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT", "services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS", "services.ollama.models_dir": "LAB_OLLAMA_MODELS_DIR", @@ -183,6 +185,8 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_heimdall_backend_port "${LAB_HEIMDALL_HTTP_PORT:-}" export_if_unset TF_VAR_homepage_backend_host "${LAB_HOMEPAGE_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" export_if_unset TF_VAR_homepage_backend_port "${LAB_HOMEPAGE_HTTP_PORT:-}" + export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" + export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}" export_if_unset TF_VAR_gitops_repo_url "${LAB_GITOPS_REPO_URL:-}" export_if_unset TF_VAR_worker_tailscale_enabled "${LAB_PIMOX_WORKER_TAILSCALE_ENABLED:-}" export_if_unset TF_VAR_worker_tailscale_accept_routes "${LAB_PIMOX_WORKER_TAILSCALE_ACCEPT_ROUTES:-}" diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 53f3e7d..7b99ab9 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -48,6 +48,10 @@ mapping = { "services.heimdall.install_dir": "LAB_HEIMDALL_INSTALL_DIR", "services.heimdall.http_port": "LAB_HEIMDALL_HTTP_PORT", "services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL", + "services.homepage.http_port": "LAB_HOMEPAGE_HTTP_PORT", + "services.homepage.public_url": "LAB_HOMEPAGE_PUBLIC_URL", + "services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT", + "services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL", "services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT", "services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS", "services.ollama.models_dir": "LAB_OLLAMA_MODELS_DIR", @@ -180,6 +184,10 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_gitea_backend_port "${LAB_GITEA_HTTP_PORT:-}" export_if_unset TF_VAR_heimdall_backend_host "${LAB_HEIMDALL_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" export_if_unset TF_VAR_heimdall_backend_port "${LAB_HEIMDALL_HTTP_PORT:-}" + export_if_unset TF_VAR_homepage_backend_host "${LAB_HOMEPAGE_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" + export_if_unset TF_VAR_homepage_backend_port "${LAB_HOMEPAGE_HTTP_PORT:-}" + export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" + export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}" export_if_unset TF_VAR_gitops_repo_url "${LAB_GITOPS_REPO_URL:-}" export_if_unset TF_VAR_worker_tailscale_enabled "${LAB_PIMOX_WORKER_TAILSCALE_ENABLED:-}" export_if_unset TF_VAR_worker_tailscale_accept_routes "${LAB_PIMOX_WORKER_TAILSCALE_ACCEPT_ROUTES:-}" diff --git a/scripts/generate-heimdall-links b/scripts/generate-heimdall-links index 879365a..4a0f41a 100755 --- a/scripts/generate-heimdall-links +++ b/scripts/generate-heimdall-links @@ -33,6 +33,7 @@ HOST_METADATA = { "demos": ("Demo Apps", "Static browser-side demo catalog", "#2563eb", "Demos"), "heimdall": ("Heimdall", "Homelab service dashboard", "#7c3aed", "Heimdall"), "homepage": ("Homepage", "Generated homelab operations dashboard", "#0284c7", "Homepage"), + "jellyfin": ("Jellyfin", "Media streaming server", "#7c3aed", "Jellyfin"), "matrix": ("Matrix", "Matrix Synapse homeserver", "#0f172a", "Matrix"), "element": ("Element", "Matrix web client", "#0ea5e9", "Element"), "grafana": ("Grafana", "Monitoring dashboards", "#f97316", "Grafana"),