From cdbc976b8a63851bcb35b4926a9044b1507b1aac Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Fri, 24 Apr 2026 20:31:55 +0200 Subject: [PATCH] Use Traefik container IP for edge E2E --- scripts/edge-gateway-e2e.mjs | 45 ++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/scripts/edge-gateway-e2e.mjs b/scripts/edge-gateway-e2e.mjs index 4ff3ff53..04c38393 100644 --- a/scripts/edge-gateway-e2e.mjs +++ b/scripts/edge-gateway-e2e.mjs @@ -75,9 +75,12 @@ function normalizeBaseUrl(url) { return String(url || "").replace(/\/+$/, ""); } -function baseUrlWithHost(baseUrl, host) { +function baseUrlWithHost(baseUrl, host, port = null) { const url = new URL(normalizeBaseUrl(baseUrl)); url.hostname = host; + if (port !== null) { + url.port = port; + } return normalizeBaseUrl(url.toString()); } @@ -115,12 +118,43 @@ async function readDefaultGatewayHost() { } } -async function candidateApiBaseUrls(baseUrl) { +async function readComposeServiceHost(rootDir, composeProject, serviceName) { + const ps = await runCommand("docker", composeArgs(composeProject, ["ps", "-q", serviceName]), { + cwd: rootDir, + allowFailure: true, + }); + const containerId = String(ps.stdout || "").trim().split(/\s+/).find(Boolean); + if (!containerId) { + return null; + } + + const inspection = await runCommand("docker", [ + "inspect", + "-f", + "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", + containerId, + ], { + cwd: rootDir, + allowFailure: true, + }); + const host = String(inspection.stdout || "").trim().split(/\s+/).find((value) => /^\d{1,3}(?:\.\d{1,3}){3}$/.test(value)); + + return host || null; +} + +async function candidateApiBaseUrls(baseUrl, rootDir, composeProject) { const normalized = normalizeBaseUrl(baseUrl); const candidates = [normalized]; const url = new URL(normalized); if (["localhost", "127.0.0.1", "::1"].includes(url.hostname)) { + if (rootDir && composeProject) { + const traefikHost = await readComposeServiceHost(rootDir, composeProject, "traefik"); + if (traefikHost) { + candidates.push(baseUrlWithHost(normalized, traefikHost, "")); + } + } + const gatewayHost = await readDefaultGatewayHost(); if (gatewayHost) { candidates.push(baseUrlWithHost(normalized, gatewayHost)); @@ -153,8 +187,8 @@ async function ensureComposeServices(rootDir, composeProject) { }); } -async function waitForApiReady(baseUrl, attempts = 60) { - const candidates = await candidateApiBaseUrls(baseUrl); +async function waitForApiReady(baseUrl, rootDir, composeProject, attempts = 60) { + const candidates = await candidateApiBaseUrls(baseUrl, rootDir, composeProject); let lastError = "API never responded"; for (let attempt = 0; attempt < attempts; attempt += 1) { @@ -418,7 +452,8 @@ async function main() { try { await ensureComposeServices(rootDir, composeProject); - baseUrl = await waitForApiReady(baseUrl); + baseUrl = await waitForApiReady(baseUrl, rootDir, composeProject); + process.stdout.write(`Using API base URL ${baseUrl}\n`); fixture = await runPhpFixture(rootDir, composeProject, "create"); const authToken = String(fixture.auth_token || "");