Skip to content

Commit

Permalink
fix: retry skopeo copy command
Browse files Browse the repository at this point in the history
DockerHub being instable recently introduced new flakiness to our tests, which points towards our "skopeo copy" command being a bit too fragile.
this commit introduces a retry mechnanism on that command, always retrying to pull the image.

a more efficient solution would be inspecting the error causing the instability and retrying only on that, but this should be good enough as we'll waste only 2 seconds at worst.
  • Loading branch information
Shesekino committed Feb 11, 2020
1 parent c780d10 commit b752a6f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/scanner/images/skopeo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as sleep from 'sleep-promise';

import * as processWrapper from '../../common/process';
import * as config from '../../common/config';
import * as credentials from './credentials';
Expand Down Expand Up @@ -41,7 +43,24 @@ export async function pull(
args.push({body: prefixRespository(image, SkopeoRepositoryType.ImageRegistry), sanitise: false});
args.push({body: prefixRespository(destination, SkopeoRepositoryType.DockerArchive), sanitise: false});

processWrapper.exec('skopeo', ...args);
await pullWithRetry(args);
}

async function pullWithRetry(args: Array<processWrapper.IProcessArgument>): Promise<void> {
const MAX_ATTEMPTS = 10;
const RETRY_INTERVAL_SEC = 0.2;

for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
try {
await processWrapper.exec('skopeo', ...args);
return;
} catch (err) {
if (attempt + 1 > MAX_ATTEMPTS) {
throw err;
}
await sleep(RETRY_INTERVAL_SEC * 1000);
}
}
}

export function getCredentialParameters(credentials: string | undefined): Array<processWrapper.IProcessArgument> {
Expand Down

0 comments on commit b752a6f

Please sign in to comment.