Open-source personal finance manager. Self-hosted, privacy-first.
fix(frontend): make the nginx proxy work on any container platform (#696)
Junior Vidotti75435c14b5d9
diff --git a/charts/securo/templates/frontend/configmap-nginx.yaml b/charts/securo/templates/frontend/configmap-nginx.yamlindex b0317828..a4941249 100644--- a/charts/securo/templates/frontend/configmap-nginx.yaml+++ b/charts/securo/templates/frontend/configmap-nginx.yaml@@ -13,8 +13,16 @@ data:index index.html;# API proxy to backend.+ # Resolve the backend hostname at request time instead of caching the IP+ # at startup. Without this, Nginx pins the upstream IP when the config+ # loads and returns 502s after the backend pod is recreated with a new+ # IP. Using a variable in proxy_pass forces re-resolution; NGINX_RESOLVER+ # is derived from the pod's own /etc/resolv.conf (cluster DNS) by the+ # image's docker-entrypoint.d/19-resolver.envsh.location /api/ {- proxy_pass ${BACKEND_URL};+ resolver ${NGINX_RESOLVER} valid=5s;+ set $upstream ${BACKEND_URL};+ proxy_pass $upstream;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;diff --git a/charts/securo/templates/frontend/deployment.yaml b/charts/securo/templates/frontend/deployment.yamlindex f2ea8cc5..2bef493b 100644--- a/charts/securo/templates/frontend/deployment.yaml+++ b/charts/securo/templates/frontend/deployment.yaml@@ -17,6 +17,7 @@ spec:metadata:annotations:checksum/config: {{ include (print $.Template.BasePath "/common/configmap.yaml") . | sha256sum }}+ checksum/nginx-config: {{ include (print $.Template.BasePath "/frontend/configmap-nginx.yaml") . | sha256sum }}labels:{{- include "securo.selectorLabels" . | nindent 8 }}app.kubernetes.io/component: frontenddiff --git a/frontend/Dockerfile b/frontend/Dockerfileindex 4229cc16..2a3fb5a2 100644--- a/frontend/Dockerfile+++ b/frontend/Dockerfile@@ -17,4 +17,12 @@ FROM nginxinc/nginx-unprivileged:alpineCOPY --from=build /app/dist /usr/share/nginx/htmlCOPY default.conf.template /etc/nginx/templates/default.conf.template+# Have the image derive the DNS resolver from /etc/resolv.conf, so the same+# image proxies to the backend on Docker, Podman, Kubernetes and Railway with+# no per-platform configuration. 19-resolver.envsh turns that into+# NGINX_RESOLVER (with a Docker fallback) for the config template; setting+# NGINX_RESOLVER explicitly still overrides both.+ENV NGINX_ENTRYPOINT_LOCAL_RESOLVERS=1+COPY --chmod=755 docker-entrypoint.d/19-resolver.envsh /docker-entrypoint.d/+EXPOSE 8080diff --git a/frontend/default.conf.template b/frontend/default.conf.templateindex acd83726..98c1a417 100644--- a/frontend/default.conf.template+++ b/frontend/default.conf.template@@ -9,9 +9,12 @@ server {# upstream IP when the config loads and returns 502s after the backend# container is recreated with a new IP (e.g. selective redeploys where the# frontend container is left running). Using a variable in proxy_pass forces- # re-resolution; the resolver below is the Docker daemon's internal DNS.+ # re-resolution. NGINX_RESOLVER is derived from the platform's own+ # /etc/resolv.conf at startup (see docker-entrypoint.d/19-resolver.envsh),+ # so this works as-is on Docker, Podman, Kubernetes and Railway. Set+ # NGINX_RESOLVER explicitly to override that detection.location /api/ {- resolver 127.0.0.11 valid=5s;+ resolver ${NGINX_RESOLVER} valid=5s;set $upstream ${BACKEND_URL};proxy_pass $upstream;proxy_set_header Host $host;diff --git a/frontend/docker-entrypoint.d/19-resolver.envsh b/frontend/docker-entrypoint.d/19-resolver.envshnew file mode 100755index 00000000..11f81d06--- /dev/null+++ b/frontend/docker-entrypoint.d/19-resolver.envsh@@ -0,0 +1,13 @@+#!/bin/sh+# Resolver nginx uses to re-resolve BACKEND_URL at request time.+#+# Precedence: an explicit NGINX_RESOLVER wins; otherwise take the platform's+# own resolver, which 15-local-resolvers.envsh reads from /etc/resolv.conf+# (it already brackets IPv6 addresses); otherwise fall back to Docker's+# embedded DNS. This is what lets the same image work unchanged on Docker,+# Podman, Kubernetes and Railway (whose internal DNS is [fd12::10]).+#+# Deliberately no `set -e`: the entrypoint *sources* .envsh files, so it would+# leak into the entrypoint's own shell and change its semantics.+: "${NGINX_RESOLVER:=${NGINX_LOCAL_RESOLVERS:-127.0.0.11}}"+export NGINX_RESOLVER