Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix(docker): make the frontend's backend upstream configurable
Pouzor3b6b472f9704
diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.ymlindex dde50c0..4477d29 100644--- a/.github/workflows/docker-ci.yml+++ b/.github/workflows/docker-ci.yml@@ -59,6 +59,32 @@ jobs:STATUS=$(curl -so /dev/null -w "%{http_code}" http://localhost:3000/)[ "$STATUS" = "200" ] || { echo "Frontend returned $STATUS"; exit 1; }+ # ── Smoke: nginx proxies the API to the default upstream (backend:8000) ───+ - name: Smoke — frontend proxies /api to the backend+ run: |+ STATUS=$(curl -so /dev/null -w "%{http_code}" http://localhost:3000/api/v1/health)+ [ "$STATUS" = "200" ] || { echo "Proxied health returned $STATUS"; exit 1; }++ # ── Smoke: BACKEND_UPSTREAM reaches a backend off the compose network ─────+ # The backend-on-network_mode:host setup (#512): `backend` does not resolve,+ # so the frontend must proxy to the host. Same image, run outside compose.+ - name: Smoke — BACKEND_UPSTREAM overrides the proxy target+ run: |+ IMAGE=$(docker inspect --format '{{.Image}}' \+ "$(docker compose -f docker-compose.yml -f docker-compose.ci.yml ps -q frontend)")+ docker run -d --name frontend-upstream \+ --add-host host.docker.internal:host-gateway \+ -e BACKEND_UPSTREAM=host.docker.internal:8000 \+ -p 3001:80 "$IMAGE"+ for i in $(seq 1 15); do+ STATUS=$(curl -so /dev/null -w "%{http_code}" http://localhost:3001/api/v1/health || true)+ [ "$STATUS" = "200" ] && exit 0+ sleep 1+ done+ echo "Proxied health via BACKEND_UPSTREAM returned $STATUS" >&2+ docker logs frontend-upstream+ exit 1+# ── Tier 3: integration tests against the live stack ──────────────────────- uses: actions/setup-python@v5with:@@ -83,4 +109,6 @@ jobs:- name: Stop stackif: always()- run: docker compose -f docker-compose.yml -f docker-compose.ci.yml down -v+ run: |+ docker rm -f frontend-upstream 2>/dev/null || true+ docker compose -f docker-compose.yml -f docker-compose.ci.yml down -vdiff --git a/Dockerfile.frontend b/Dockerfile.frontendindex 5e8db73..77f530b 100644--- a/Dockerfile.frontend+++ b/Dockerfile.frontend@@ -37,18 +37,33 @@ COPY docker/nginx.conf docker/nginx.standalone.conf /tmp/nginx-conf/COPY docker/nginx.subpath.conf.template docker/nginx.standalone.subpath.conf.template /tmp/nginx-conf/# ash with pipefail: the base-path normalization below pipes printf into sed.SHELL ["/bin/ash", "-eo", "pipefail", "-c"]+# The full config proxies to ${BACKEND_UPSTREAM}. It goes to /etc/nginx/templates,+# which the stock entrypoint renders with envsubst into conf.d at container start, so+# the upstream is a runtime setting: with the backend on network_mode: host, run the+# frontend with BACKEND_UPSTREAM=host.docker.internal:8000. The standalone config+# has no upstream and stays a plain conf.d file.RUN set -eu; \- if [ "$VITE_STANDALONE" = "true" ]; then variant=nginx.standalone; else variant=nginx; fi; \+ if [ "$VITE_STANDALONE" = "true" ]; then \+ variant=nginx.standalone; out=/etc/nginx/conf.d/default.conf; \+ else \+ variant=nginx; out=/etc/nginx/templates/default.conf.template; \+ mkdir -p /etc/nginx/templates; \+ fi; \base=$(printf '%s' "${VITE_BASE_PATH:-/}" | sed -e 's#^/*#/#' -e 's#/*$#/#' -e 's#//*#/#g'); \[ -n "$base" ] || base=/; \mkdir -p "/usr/share/nginx/html${base}"; \cp -a /tmp/dist/. "/usr/share/nginx/html${base}"; \if [ "$base" = "/" ]; then \- cp "/tmp/nginx-conf/${variant}.conf" /etc/nginx/conf.d/default.conf; \+ cp "/tmp/nginx-conf/${variant}.conf" "$out"; \else \sed -e "s#__BASE_NO_SLASH__#${base%/}#g" -e "s#__BASE__#${base}#g" \- "/tmp/nginx-conf/${variant}.subpath.conf.template" > /etc/nginx/conf.d/default.conf; \+ "/tmp/nginx-conf/${variant}.subpath.conf.template" > "$out"; \fi; \rm -rf /tmp/dist /tmp/nginx-conf+# Only BACKEND_UPSTREAM is substituted: the filter keeps envsubst away from nginx's+# own $host, $uri, $http_upgrade… even if the container env defines a same-named var.+ENV BACKEND_UPSTREAM=backend:8000 \+ NGINX_ENVSUBST_FILTER=^BACKEND_UPSTREAM$+EXPOSE 80diff --git a/INSTALLATION.md b/INSTALLATION.mdindex ea2c5ec..ac4e7ea 100644--- a/INSTALLATION.md+++ b/INSTALLATION.md@@ -94,10 +94,31 @@ then `docker compose up -d`. Caveats:- The backend binds `8000` directly on the host, with no port mapping and nonetwork isolation from other host services.- `frontend` and `mcp` reach the backend at `http://backend:8000` over the- `homelable` bridge; once the backend leaves that network they need- `http://127.0.0.1:8000` instead. Set `BACKEND_URL` on `mcp`, and for the front- end either give it `network_mode: host` too or point its nginx proxy at the- host address.+ `homelable` bridge. Once the backend leaves that network the name `backend`+ no longer resolves — nginx refuses to start with+ `host not found in upstream "backend"` and the frontend restart-loops. Keep+ both services on the bridge and point them at the host instead; the compose+ files carry these lines commented out under each service:++ ```yaml+ frontend:+ environment:+ BACKEND_UPSTREAM: "host.docker.internal:8000"+ extra_hosts:+ - "host.docker.internal:host-gateway"++ mcp:+ environment:+ BACKEND_URL: "http://host.docker.internal:8000"+ extra_hosts:+ - "host.docker.internal:host-gateway"+ ```++ `BACKEND_UPSTREAM` (default `backend:8000`) is the `host:port` the frontend's+ nginx proxies `/api`, `/ws`, `/docs`, `/redoc` and `/openapi.json` to; it is+ read at container start, so the prebuilt image honours it. The UI stays on+ port `3000`. A host firewall that drops traffic from Docker subnets to the+ host (some `ufw` setups) must allow port `8000` from them.The alternative, if you would rather keep the backend isolated, is a **macvlan**network, which gives the container its own MAC and IP on your physical LAN.diff --git a/docker-compose.prebuilt.yml b/docker-compose.prebuilt.ymlindex 25c6927..2ee9629 100644--- a/docker-compose.prebuilt.yml+++ b/docker-compose.prebuilt.yml@@ -29,6 +29,13 @@ services:- backendnetworks:- homelable+ # Backend on network_mode: host (see INSTALLATION.md, "Scanning from Docker")?+ # `backend` no longer resolves from this network; keep the frontend here and+ # point nginx at the host instead:+ # environment:+ # BACKEND_UPSTREAM: "host.docker.internal:8000"+ # extra_hosts:+ # - "host.docker.internal:host-gateway"mcp:image: ghcr.io/pouzor/homelable-mcp:latest@@ -43,6 +50,10 @@ services:- backendnetworks:- homelable+ # Backend on network_mode: host? Use BACKEND_URL "http://host.docker.internal:8000"+ # above, and uncomment:+ # extra_hosts:+ # - "host.docker.internal:host-gateway"volumes:backend_data:diff --git a/docker-compose.yml b/docker-compose.ymlindex 11456c1..8ec955b 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -44,6 +44,10 @@ services:- backendnetworks:- homelable+ # Backend on network_mode: host? Use BACKEND_URL "http://host.docker.internal:8000"+ # above, and uncomment:+ # extra_hosts:+ # - "host.docker.internal:host-gateway"frontend:build:@@ -60,6 +64,13 @@ services:- backendnetworks:- homelable+ # Backend on network_mode: host (see INSTALLATION.md, "Scanning from Docker")?+ # `backend` no longer resolves from this network; keep the frontend here and+ # point nginx at the host instead:+ # environment:+ # BACKEND_UPSTREAM: "host.docker.internal:8000"+ # extra_hosts:+ # - "host.docker.internal:host-gateway"volumes:backend_data:diff --git a/docker/nginx.conf b/docker/nginx.confindex c1538dc..028b3cc 100644--- a/docker/nginx.conf+++ b/docker/nginx.conf@@ -1,3 +1,9 @@+# Full-mode nginx config, served at the root. Installed as an nginx template:+# the image renders ${BACKEND_UPSTREAM} at container start (default backend:8000,+# see Dockerfile.frontend), so the API can live somewhere other than the compose+# `backend` service — e.g. host.docker.internal:8000 when the backend runs with+# network_mode: host.+server {listen 80;server_name _;@@ -6,7 +12,7 @@ server {# Proxy WebSocket (must be before /api/ to take priority)location /api/v1/status/ws/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";@@ -16,7 +22,7 @@ server {# Proxy API to backendlocation /api/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}@@ -25,26 +31,26 @@ server {# generates. Outside /api/, so they need their own blocks or the SPA# fallback below swallows them. See docs/api.md.location /docs {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location /redoc {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location = /openapi.json {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}# Proxy legacy /ws/ pathlocation /ws/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";diff --git a/docker/nginx.subpath.conf.template b/docker/nginx.subpath.conf.templateindex 447811d..bd5715e 100644--- a/docker/nginx.subpath.conf.template+++ b/docker/nginx.subpath.conf.template@@ -4,6 +4,9 @@# __BASE__ is the prefix with its trailing slash, __BASE_NO_SLASH__ without it. A# default build keeps docker/nginx.conf and this file is never read.#+# Like docker/nginx.conf, the result is installed as an nginx template, so+# ${BACKEND_UPSTREAM} is only rendered at container start (see Dockerfile.frontend).+## The static build is copied to /usr/share/nginx/html__BASE__, so every block below# uses plain `root` semantics — `alias` plus `try_files` mis-resolves $uri.#@@ -26,7 +29,7 @@ server {# WebSocket (must come before the API block to take priority)location __BASE__api/v1/status/ws/ {- proxy_pass http://backend:8000/api/v1/status/ws/;+ proxy_pass http://${BACKEND_UPSTREAM}/api/v1/status/ws/;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";@@ -35,7 +38,7 @@ server {}location __BASE__api/ {- proxy_pass http://backend:8000/api/;+ proxy_pass http://${BACKEND_UPSTREAM}/api/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}@@ -44,26 +47,26 @@ server {# the origin root (/openapi.json), which the stripped-prefix block below# serves, so the page works under the prefix too.location __BASE__docs {- proxy_pass http://backend:8000/docs;+ proxy_pass http://${BACKEND_UPSTREAM}/docs;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location __BASE__redoc {- proxy_pass http://backend:8000/redoc;+ proxy_pass http://${BACKEND_UPSTREAM}/redoc;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location = __BASE__openapi.json {- proxy_pass http://backend:8000/openapi.json;+ proxy_pass http://${BACKEND_UPSTREAM}/openapi.json;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}# Legacy /ws/ pathlocation __BASE__ws/ {- proxy_pass http://backend:8000/ws/;+ proxy_pass http://${BACKEND_UPSTREAM}/ws/;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";@@ -78,7 +81,7 @@ server {# --- prefix already stripped by the front proxy -----------------------------# No redirect to __BASE__ here: the front proxy would strip it again and loop.location /api/v1/status/ws/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";@@ -87,31 +90,31 @@ server {}location /api/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location /docs {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location /redoc {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location = /openapi.json {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}location /ws/ {- proxy_pass http://backend:8000;+ proxy_pass http://${BACKEND_UPSTREAM};proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";