Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(docker): let a user's default.conf or a read-only conf.d skip the render

Pouzord4c82a799ddf
diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml
index ca83668..69bdd10 100644
--- a/.github/workflows/docker-ci.yml
+++ b/.github/workflows/docker-ci.yml
@@ -88,6 +88,8 @@ jobs:
# ── Smoke: a user's own conf.d/default.conf is left alone ─────────────────
# The start-time render must never write over a bind-mounted config: a
# read-write mount would be clobbered on the host, a :ro one would crash-loop.
+ # Run off the compose network on purpose: the user's config replaces
+ # homelable.conf, so nothing may still need `backend` to resolve.
- name: Smoke — a bind-mounted default.conf is served and untouched
run: |
IMAGE=$(docker inspect --format '{{.Image}}' \
diff --git a/Dockerfile.frontend b/Dockerfile.frontend
index a9ca308..7b62868 100644
--- a/Dockerfile.frontend
+++ b/Dockerfile.frontend
@@ -35,6 +35,7 @@ ARG VITE_STANDALONE=false
ARG VITE_BASE_PATH=/
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/
+COPY docker/18-homelable-config.envsh /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,
@@ -46,10 +47,11 @@ SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
# The full config lives in conf.d/homelable.conf, never default.conf: the entrypoint
# writes its output without looking at what is there, so rendering onto default.conf
# would clobber a config a user bind-mounts over it (or crash-loop on a :ro mount).
-# The stock default.conf is removed; a mounted one still sorts first and stays the
-# default server on :80. A copy pre-rendered with the default upstream ships in
-# conf.d, so a container that cannot write conf.d (read_only, non-root user) keeps
-# serving exactly what it did before the upstream became configurable.
+# The stock default.conf is removed, and a copy pre-rendered with the default
+# upstream ships in conf.d. docker/18-homelable-config.envsh runs just before the
+# render: a user's default.conf replaces homelable.conf outright, and a read-only
+# conf.d keeps the pre-rendered copy — both behave as before the upstream became
+# configurable.
RUN set -eu; \
if [ "$VITE_STANDALONE" = "true" ]; then \
variant=nginx.standalone; out=/etc/nginx/conf.d/default.conf; \
@@ -71,6 +73,7 @@ RUN set -eu; \
if [ "$variant" = "nginx" ]; then \
BACKEND_UPSTREAM=backend:8000 envsubst '${BACKEND_UPSTREAM}' \
< "$out" > /etc/nginx/conf.d/homelable.conf; \
+ install -m 0755 /tmp/nginx-conf/18-homelable-config.envsh /docker-entrypoint.d/; \
fi; \
rm -rf /tmp/dist /tmp/nginx-conf
diff --git a/docker/18-homelable-config.envsh b/docker/18-homelable-config.envsh
new file mode 100755
index 0000000..ef5121e
--- /dev/null
+++ b/docker/18-homelable-config.envsh
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Sourced by the nginx entrypoint just before 20-envsubst-on-templates.sh, which
+# renders templates/homelable.conf.template into conf.d/homelable.conf (see
+# Dockerfile.frontend). Exporting NGINX_ENVSUBST_TEMPLATE_DIR to a missing path
+# makes that script skip the render; the export reaches it because .envsh files
+# share the entrypoint's shell.
+#
+# Two cases where the render must not run:
+# - conf.d/default.conf exists. The image ships none, so it is the user's own,
+# bind-mounted: it replaces ours, exactly as it did before homelable.conf
+# existed. Leaving ours beside it would still need `backend` to resolve, and
+# a frontend on network_mode: host has no such name.
+# - conf.d is not writable (read_only container). The render would abort the
+# entrypoint; the homelable.conf pre-rendered at build time is kept instead.
+
+homelable_conf=/etc/nginx/conf.d/homelable.conf
+
+if [ -e /etc/nginx/conf.d/default.conf ]; then
+ entrypoint_log "18-homelable-config.envsh: info: conf.d/default.conf provided, using it instead of homelable.conf"
+ export NGINX_ENVSUBST_TEMPLATE_DIR=/nonexistent
+ rm -f "$homelable_conf" 2>/dev/null \
+ || entrypoint_log "18-homelable-config.envsh: warning: could not remove $homelable_conf (read-only file system?)"
+elif ! touch "$homelable_conf" 2>/dev/null; then
+ entrypoint_log "18-homelable-config.envsh: info: conf.d is read-only, keeping the built-in homelable.conf (BACKEND_UPSTREAM ignored)"
+ export NGINX_ENVSUBST_TEMPLATE_DIR=/nonexistent
+fi
+
+unset homelable_conf