Skip to content

Commit b0f7b7d

Browse files
committed
Retry transient Zitadel issuer mismatches
1 parent 4a0aa67 commit b0f7b7d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

scripts/terrarium-zitadel-sync.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ async function dockerRun(args: string[]): Promise<string> {
1515
return await runText(["docker", ...args], PREFIX);
1616
}
1717

18+
async function dockerRunWithRetry(args: string[], label: string): Promise<string> {
19+
let lastError = "";
20+
for (let attempt = 0; attempt < WAIT_ATTEMPTS; attempt += 1) {
21+
const result = await runAllowFailure(["docker", ...args]);
22+
if (result.exitCode === 0) {
23+
return result.stdout;
24+
}
25+
const stderr = result.stderr.trim();
26+
const stdout = result.stdout.trim();
27+
lastError = stderr || stdout || `${label} failed`;
28+
const combined = `${stdout}\n${stderr}`;
29+
if (!combined.includes("issuer does not match")) {
30+
throw new Error(lastError);
31+
}
32+
await Bun.sleep(WAIT_INTERVAL_MS);
33+
}
34+
throw new Error(`timed out waiting for ${label}: ${lastError}`);
35+
}
36+
1837
async function waitForFile(path: string, label: string): Promise<void> {
1938
for (let attempt = 0; attempt < WAIT_ATTEMPTS; attempt += 1) {
2039
if (existsSync(path)) {
@@ -111,8 +130,8 @@ export async function idpSyncCmd(configPath = DEFAULT_CONFIG_PATH): Promise<void
111130
tofuImage
112131
];
113132

114-
await dockerRun([...commonArgs, "init", "-input=false"]);
115-
await dockerRun([...commonArgs, "apply", "-input=false", "-auto-approve"]);
133+
await dockerRunWithRetry([...commonArgs, "init", "-input=false"], "OpenTofu init");
134+
await dockerRunWithRetry([...commonArgs, "apply", "-input=false", "-auto-approve"], "OpenTofu apply");
116135
const outputsJson = await dockerRun([...commonArgs, "output", "-json"]);
117136
writeIfChanged(outputsPath, outputsJson.endsWith("\n") ? outputsJson : `${outputsJson}\n`);
118137

0 commit comments

Comments
 (0)