src: refactor cleanup logic to expose buildkitd.log
Previosuly, we only killed the buildkitd process and unmounted if builderInfo was non null. This was wrong cause we could have setup builkdkitd, but failed after that step. This would then rely on the last ditch effort by the post action to cleanup. We now change the proc kill and unmount to happen on any build error.
This commit is contained in:
parent
8d0da8c56b
commit
54bc4e0788
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
70
src/main.ts
70
src/main.ts
|
@ -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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue