Use Traefik container IP for edge E2E
This commit is contained in:
@@ -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 || "");
|
||||
|
||||
Reference in New Issue
Block a user