mirror of
https://github.com/docker/build-push-action.git
synced 2025-08-10 02:22:11 +00:00
Merge pull request #115 from useblacksmith/buildx-ratelimit
src: add a retry with backoff to combat 429s when downloading buildkit
This commit is contained in:
commit
e09a08878e
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
23
src/main.ts
23
src/main.ts
@ -27,13 +27,34 @@ const buildxVersion = 'v0.17.0';
|
|||||||
const mountPoint = '/var/lib/buildkit';
|
const mountPoint = '/var/lib/buildkit';
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
async function retryWithBackoff<T>(operation: () => Promise<T>, maxRetries: number = 5, initialBackoffMs: number = 200): Promise<T> {
|
||||||
|
let lastError: Error = new Error('No error occurred');
|
||||||
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
|
try {
|
||||||
|
return await operation();
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error;
|
||||||
|
if (error.message?.includes('429') || error.status === 429) {
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
const backoffMs = initialBackoffMs * Math.pow(2, attempt);
|
||||||
|
core.info(`Rate limited (429). Retrying in ${backoffMs}ms...`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, backoffMs));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw lastError;
|
||||||
|
}
|
||||||
|
|
||||||
async function setupBuildx(version: string, toolkit: Toolkit): Promise<void> {
|
async function setupBuildx(version: string, toolkit: Toolkit): Promise<void> {
|
||||||
let toolPath;
|
let toolPath;
|
||||||
const standalone = await toolkit.buildx.isStandalone();
|
const standalone = await toolkit.buildx.isStandalone();
|
||||||
|
|
||||||
if (!(await toolkit.buildx.isAvailable()) || version) {
|
if (!(await toolkit.buildx.isAvailable()) || version) {
|
||||||
await core.group(`Download buildx from GitHub Releases`, async () => {
|
await core.group(`Download buildx from GitHub Releases`, async () => {
|
||||||
toolPath = await toolkit.buildxInstall.download(version || 'latest', true);
|
toolPath = await retryWithBackoff(() => toolkit.buildxInstall.download(version || 'latest', true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user