1
0
Fork 0
mirror of https://github.com/docker/build-push-action.git synced 2025-05-06 21:49:33 +02:00

Merge pull request #73 from useblacksmith/socket-cat

src: refactor cleanup logic to expose buildkitd.log
This commit is contained in:
Aditya Maru 2024-12-16 19:40:39 -05:00 committed by GitHub
commit 7227817bb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 37 deletions

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -307,46 +307,50 @@ actionsToolkit.run(
} }
await core.group('Cleaning up Blacksmith builder', async () => { await core.group('Cleaning up Blacksmith builder', async () => {
if (builderInfo.addr) { try {
try { let exportRes;
let exportRes; if (!buildError) {
if (!buildError) { const buildxHistory = new BuildxHistory();
const buildxHistory = new BuildxHistory(); exportRes = await buildxHistory.export({
exportRes = await buildxHistory.export({ refs: ref ? [ref] : []
refs: ref ? [ref] : [] });
}); }
} await shutdownBuildkitd();
await shutdownBuildkitd(); core.info('Shutdown buildkitd');
core.info('Shutdown buildkitd'); for (let attempt = 1; attempt <= 10; attempt++) {
for (let attempt = 1; attempt <= 10; attempt++) { try {
try { await execAsync(`sudo umount ${mountPoint}`);
await execAsync(`sudo umount ${mountPoint}`); core.debug(`${mountPoint} has been unmounted`);
core.debug(`${mountPoint} has been unmounted`); break;
break; } catch (error) {
} catch (error) { if (attempt === 10) {
if (attempt === 10) { throw error;
throw error;
}
core.warning(`Unmount failed, retrying (${attempt}/10)...`);
await new Promise(resolve => setTimeout(resolve, 300));
} }
core.warning(`Unmount failed, retrying (${attempt}/10)...`);
await new Promise(resolve => setTimeout(resolve, 300));
} }
core.info('Unmounted device'); }
core.info('Unmounted device');
if (builderInfo.addr) {
if (!buildError) { if (!buildError) {
await reporter.reportBuildCompleted(exportRes, builderInfo.buildId, ref, buildDurationSeconds, builderInfo.exposeId); await reporter.reportBuildCompleted(exportRes, builderInfo.buildId, ref, buildDurationSeconds, builderInfo.exposeId);
} else { } else {
try {
const buildkitdLog = fs.readFileSync('buildkitd.log', 'utf8');
core.info('buildkitd.log contents:');
core.info(buildkitdLog);
} catch (error) {
core.warning(`Failed to read buildkitd.log: ${error.message}`);
}
await reporter.reportBuildFailed(builderInfo.buildId, buildDurationSeconds, builderInfo.exposeId); await reporter.reportBuildFailed(builderInfo.buildId, buildDurationSeconds, builderInfo.exposeId);
} }
} catch (error) { }
core.warning(`Error during Blacksmith builder shutdown: ${error.message}`); } catch (error) {
await reporter.reportBuildPushActionFailure(error); core.warning(`Error during Blacksmith builder shutdown: ${error.message}`);
await reporter.reportBuildPushActionFailure(error);
} finally {
if (buildError) {
try {
const buildkitdLog = fs.readFileSync('buildkitd.log', 'utf8');
core.info('buildkitd.log contents:');
core.info(buildkitdLog);
} catch (error) {
core.warning(`Failed to read buildkitd.log: ${error.message}`);
}
} }
} }
}); });

View file

@ -177,7 +177,7 @@ export async function startAndConfigureBuildkitd(parallelism: number, device: st
// Change permissions on the buildkitd socket to allow non-root access // Change permissions on the buildkitd socket to allow non-root access
const startTime = Date.now(); const startTime = Date.now();
const timeout = 5000; // 5 seconds in milliseconds const timeout = 10000; // 10 seconds in milliseconds
while (Date.now() - startTime < timeout) { while (Date.now() - startTime < timeout) {
if (fs.existsSync('/run/buildkit/buildkitd.sock')) { if (fs.existsSync('/run/buildkit/buildkitd.sock')) {
@ -189,7 +189,7 @@ export async function startAndConfigureBuildkitd(parallelism: number, device: st
} }
if (!fs.existsSync('/run/buildkit/buildkitd.sock')) { if (!fs.existsSync('/run/buildkit/buildkitd.sock')) {
throw new Error('buildkitd socket not found after 5s timeout'); throw new Error('buildkitd socket not found after 10s timeout');
} }
return buildkitdAddr; return buildkitdAddr;
} }