Skip to content

Commit 8e8e280

Browse files
committed
fix(docker/create-images-manifests): handle failure due to temp not found manifest
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 5351b91 commit 8e8e280

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

actions/docker/create-images-manifests/action.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,60 @@ runs:
203203
throw new Error(`"built-images" output is not a valid JSON: ${error}`);
204204
}
205205
206+
const sleep = (delayMs) =>
207+
new Promise((resolve) => setTimeout(resolve, delayMs));
208+
206209
const getImageDigest = async function(image) {
207210
// Check if the image already has a digest
208211
if (image.match(/@/)) {
209212
core.debug(`Image "${image}" already has a digest, skipping inspection.`);
210213
return image;
211214
}
212215
213-
const inspectImageCommand = `docker buildx imagetools inspect ${image}`;
216+
const inspectImageArgs = ["buildx", "imagetools", "inspect", image];
217+
const inspectImageCommand = `docker ${inspectImageArgs.join(" ")}`;
214218
core.debug(`Inspecting image "${image}" with command: "${inspectImageCommand}"`);
215219
216-
const { stdout } = await exec.getExecOutput(inspectImageCommand);
220+
let stdout = "";
221+
const maxAttempts = 6;
222+
const delayMs = 5000;
223+
224+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
225+
const result = await exec.getExecOutput(
226+
"docker",
227+
inspectImageArgs,
228+
{ ignoreReturnCode: true },
229+
);
230+
231+
stdout = result.stdout;
232+
233+
if (result.exitCode === 0 && stdout) {
234+
core.debug(
235+
`Inspect image "${image}" ("${inspectImageCommand}") executed: ${stdout}`
236+
);
237+
break;
238+
}
217239
218-
core.debug(`Inspect image "${image}" ("${inspectImageCommand}") executed: ${stdout}`);
240+
const commandOutput = `${result.stderr || ""}\n${stdout}`.trim();
241+
const isRetryableNotFound = /not found|manifest unknown|no such manifest/i.test(commandOutput);
242+
243+
if (!isRetryableNotFound || attempt === maxAttempts) {
244+
throw new Error(
245+
`Failed to retrieve manifest for image "${image}": ` +
246+
`"${inspectImageCommand}" failed with exit code ${result.exitCode}. ` +
247+
`Output: ${commandOutput || "<empty>"}`
248+
);
249+
}
250+
251+
core.info(
252+
[
253+
`Image "${image}" manifest is not visible yet`,
254+
`(attempt ${attempt}/${maxAttempts}).`,
255+
`Retrying in ${delayMs} ms.`,
256+
].join(" ")
257+
);
258+
await sleep(delayMs);
259+
}
219260
220261
if (!stdout) {
221262
throw new Error(`Failed to retrieve manifest for image "${image}": "${inspectImageCommand}" returned empty output`);

0 commit comments

Comments
 (0)