ci: report candidate container failures
CI / verify (push) Failing after 4m5s

This commit is contained in:
2026-09-17 23:00:19 +08:00
parent bc0545527f
commit 2f2a45f0ea
+19 -1
View File
@@ -41,6 +41,21 @@ async function waitForHealth(container, timeoutMs = 90_000) {
throw new Error("Timed out waiting for candidate health check");
}
async function reportContainerFailure(container) {
try {
const state = await container.inspect();
console.error(`Candidate status: ${state.State.Status}; health: ${state.State.Health?.Status || "unavailable"}`);
for (const check of state.State.Health?.Log?.slice(-3) || []) {
const output = check.Output?.trim();
if (output) console.error(`Health check: ${output}`);
}
const logs = await container.logs({ stdout: true, stderr: true, tail: 100 });
if (logs.length) console.error(`Candidate logs:\n${logs.toString("utf8")}`);
} catch (diagnosticError) {
console.error(`Could not read candidate diagnostics: ${diagnosticError.message}`);
}
}
async function followBuild(stream) {
const output = await new Promise((resolve, reject) => {
docker.modem.followProgress(stream, (error, events) => error ? reject(error) : resolve(events), (event) => {
@@ -93,7 +108,10 @@ try {
if (hasCurrent) await removeContainer(previous);
console.log(`Deployed ${image} on port ${port}`);
} catch (error) {
if (next) await removeContainer(candidate).catch(() => undefined);
if (next) {
await reportContainerFailure(next);
await removeContainer(candidate).catch(() => undefined);
}
if (hasCurrent) {
const rollback = docker.getContainer(previous);
await rollback.rename({ name: service });