From 42a441a7ab2e4ae364fc6ff1e335347e9abc3700 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Mon, 10 Aug 2026 00:09:22 +0200 Subject: [PATCH] =?UTF-8?q?fix(prod):=20d=C3=A9ploiement=20docker=20foncti?= =?UTF-8?q?onnel=20=E2=80=94=20API=5FBASE=5FURL=20+=20wildcard=20loopback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SameOriginHttpMessageHandler: quand Kestrel écoute sur une wildcard (0.0.0.0 / [::] — ASPNETCORE_URLS=http://+:8080 en conteneur), résoudre l'origine interne vers http://localhost: au lieu de l'adresse anycast que le HttpClient ne peut pas joindre - docker-compose.prod.yml: API_BASE_URL explicite (http://localhost:8080) pour que les appels internes du circuit Blazor ciblent le listener du conteneur et non le port hôte vu par le navigateur - docker-compose.local.yml: override pour déployer l'image locale tant que les fixes ne sont pas publiés sur Docker Hub par la CI - .gitignore: exclut les .env (secrets JWT/mots de passe) Vérifié par smoke test Playwright contre la prod (127.0.0.1:5010) : login UI → dashboard, page users, création d'utilisateur, logout : 5/5 --- .gitignore | 5 +++++ docker/docker-compose.local.yml | 10 ++++++++++ docker/docker-compose.prod.yml | 3 +++ .../Services/SameOriginHttpMessageHandler.cs | 9 +++++++++ 4 files changed, 27 insertions(+) create mode 100644 docker/docker-compose.local.yml diff --git a/.gitignore b/.gitignore index c528db7..0eb7757 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,8 @@ coverage-report*/ # Core dumps core.* templates/ + +# Secrets — never commit +.env +**/.env +docker/.env diff --git a/docker/docker-compose.local.yml b/docker/docker-compose.local.yml new file mode 100644 index 0000000..4b23c68 --- /dev/null +++ b/docker/docker-compose.local.yml @@ -0,0 +1,10 @@ +# ─── Heimdall — Override: use locally-built image with current fixes ─── +# The Docker Hub image (eltruncho/heimdall:latest) is published by CI on +# main pushes; until the fixes are pushed, deploy the local image instead. +# Usage: docker compose --env-file docker/.env -f docker/docker-compose.prod.yml -f docker/docker-compose.local.yml up -d +services: + heimdall: + image: heimdall:local + build: + context: .. + dockerfile: docker/Dockerfile diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 6fd856c..a5a7bbb 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -87,6 +87,9 @@ services: ASPNETCORE_URLS: http://+:8080 # CORS (for external agents and API clients) Cors__AllowedOrigins: ${Cors__AllowedOrigins:-*} + # Monolith: internal HTTP calls (circuit-triggered) must target the + # container's own listener, NOT the host-mapped origin the browser sees. + API_BASE_URL: ${API_BASE_URL:-http://localhost:8080} # Error tracking SENTRY_DSN: ${SENTRY_DSN} Sentry__Dsn: ${Sentry__Dsn} diff --git a/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs b/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs index 0bca067..fa01758 100644 --- a/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs +++ b/src/Heimdall.Web/Services/SameOriginHttpMessageHandler.cs @@ -61,6 +61,15 @@ public static class ApiBaseUrlResolver if (string.IsNullOrWhiteSpace(httpAddress)) return null; + // Wildcard binds (0.0.0.0 / [::]) cannot be dialed by an HttpClient — + // replace the host with loopback, keeping the bound port. + if (httpAddress.Contains("0.0.0.0", StringComparison.OrdinalIgnoreCase) + || httpAddress.Contains("[::]", StringComparison.OrdinalIgnoreCase)) + { + var port = new Uri(httpAddress).Port; + httpAddress = $"http://localhost:{port}/"; + } + // http://127.0.0.1:5000 -> http://127.0.0.1:5000/ return httpAddress.EndsWith('/') ? httpAddress : httpAddress + "/"; }