mirror of
https://github.com/docker/build-push-action.git
synced 2025-05-07 14:09:30 +02:00
src: add some idempotent cleanup safeguard in post action
This commit is contained in:
parent
2ca2ad464d
commit
9336122050
3 changed files with 39 additions and 2 deletions
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
37
src/main.ts
37
src/main.ts
|
@ -788,6 +788,43 @@ actionsToolkit.run(
|
||||||
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Check for any lingering buildkitd processes as a safeguard.
|
||||||
|
// TODO(adityamaru): Let's add an endpoint to sentry alert on this cause this
|
||||||
|
// means we've not handled some error throws in the main action.
|
||||||
|
try {
|
||||||
|
const {stdout} = await execAsync('pgrep buildkitd');
|
||||||
|
if (stdout) {
|
||||||
|
core.info('Found lingering buildkitd processes, cleaning up...');
|
||||||
|
await shutdownBuildkitd();
|
||||||
|
core.info('Shutdown buildkitd');
|
||||||
|
|
||||||
|
// Try to unmount if mounted
|
||||||
|
try {
|
||||||
|
const {stdout: mountOutput} = await execAsync(`mount | grep ${mountPoint}`);
|
||||||
|
if (mountOutput) {
|
||||||
|
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||||
|
try {
|
||||||
|
await execAsync(`sudo umount ${mountPoint}`);
|
||||||
|
core.debug(`${mountPoint} has been unmounted`);
|
||||||
|
break;
|
||||||
|
} catch (error) {
|
||||||
|
if (attempt === 3) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
core.warning(`Unmount failed, retrying (${attempt}/3)...`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.info('Unmounted device');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
core.warning(`Error during cleanup: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// pgrep returns non-zero if no processes found, which is fine.
|
||||||
|
core.debug('No lingering buildkitd processes found');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue