mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-08-23 07:27:48 +03:00
Compare commits
6 commits
00b2b44140
...
a9e7dd1024
Author | SHA1 | Date | |
---|---|---|---|
|
a9e7dd1024 | ||
|
af1b253b8d | ||
|
3c6ab92b04 | ||
|
80d22c042f | ||
|
66d7daabf8 | ||
|
bc3c5abd64 |
2 changed files with 67 additions and 8 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -522,6 +522,7 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version:
|
version:
|
||||||
|
- latest
|
||||||
- v0.11.0
|
- v0.11.0
|
||||||
- v0.10.5
|
- v0.10.5
|
||||||
steps:
|
steps:
|
||||||
|
@ -530,7 +531,7 @@ jobs:
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Install k3s
|
name: Install k3s
|
||||||
uses: crazy-max/.github/.github/actions/install-k3s@f5cb4a109b7a3b466a2ac293ef4bb13f1571acd7
|
uses: crazy-max/.github/.github/actions/install-k3s@a94383ec9e125b23907fb6fcebf7ff87964595e5
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
id: buildx
|
id: buildx
|
||||||
|
|
72
src/main.ts
72
src/main.ts
|
@ -17,6 +17,37 @@ import {ContextInfo} from '@docker/actions-toolkit/lib/types/docker/docker';
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
import * as stateHelper from './state-helper';
|
import * as stateHelper from './state-helper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retry a function with exponential backoff
|
||||||
|
*/
|
||||||
|
async function retryWithBackoff<T>(
|
||||||
|
operation: () => Promise<T>,
|
||||||
|
maxRetries: number = 3,
|
||||||
|
initialDelay: number = 1000,
|
||||||
|
maxDelay: number = 10000,
|
||||||
|
shouldRetry: (error: Error) => boolean = () => true
|
||||||
|
): Promise<T> {
|
||||||
|
let retries = 0;
|
||||||
|
let delay = initialDelay;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return await operation();
|
||||||
|
} catch (error) {
|
||||||
|
if (retries >= maxRetries || !shouldRetry(error)) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
retries++;
|
||||||
|
core.info(`Retry ${retries}/${maxRetries} after ${delay}ms due to: ${error.message}`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
|
||||||
|
// Exponential backoff with jitter
|
||||||
|
delay = Math.min(delay * 2, maxDelay) * (0.8 + Math.random() * 0.4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
actionsToolkit.run(
|
actionsToolkit.run(
|
||||||
// main
|
// main
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -175,13 +206,40 @@ actionsToolkit.run(
|
||||||
|
|
||||||
await core.group(`Booting builder`, async () => {
|
await core.group(`Booting builder`, async () => {
|
||||||
const inspectCmd = await toolkit.buildx.getCommand(await context.getInspectArgs(inputs, toolkit));
|
const inspectCmd = await toolkit.buildx.getCommand(await context.getInspectArgs(inputs, toolkit));
|
||||||
await Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
|
|
||||||
ignoreReturnCode: true
|
try {
|
||||||
}).then(res => {
|
await retryWithBackoff(
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
async () => {
|
||||||
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
// Create a promise that will timeout after 15 seconds
|
||||||
}
|
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||||
});
|
setTimeout(() => {
|
||||||
|
reject(new Error('Timeout exceeded while waiting for buildkit to initialize'));
|
||||||
|
}, 15000); // 15 second timeout
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the actual command execution promise
|
||||||
|
const execPromise = Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Race the timeout against the actual command
|
||||||
|
// If the command takes too long, we'll get the timeout error instead
|
||||||
|
return Promise.race([execPromise, timeoutPromise]);
|
||||||
|
},
|
||||||
|
3, // maxRetries - retry up to 3 times for buildkit initialization
|
||||||
|
1000, // initialDelay - start with 1 second
|
||||||
|
15000 // maxDelay - cap at 15 seconds
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
// Log the warning but continue - this matches current behavior where builds still succeed
|
||||||
|
core.warning(`Failed to bootstrap builder after multiple retries: ${error.message}`);
|
||||||
|
core.warning('Continuing execution as buildkit daemon may initialize later');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (inputs.install) {
|
if (inputs.install) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue