feat(buildx): add automatic Buildx cleanup for stale builders and end-of-run cache pruning
This commit is contained in:
+40
-9
@@ -75,6 +75,16 @@ CONFIGURATION
|
||||
platforms Array of target platforms (default: ["linux/amd64"])
|
||||
push Boolean, auto-push after build
|
||||
testDir Directory containing test_*.sh scripts
|
||||
autoCleanup Boolean, auto-prune tsdocker buildx cache (default: true)
|
||||
cleanupOnStart Boolean, prune stale tsdocker builders on startup (default: true)
|
||||
buildxPruneUntil Duration for age-based cache pruning (default: "168h")
|
||||
buildxPruneMaxUsedSpace Per-builder cache cap (default: "2gb")
|
||||
|
||||
Cleanup environment overrides:
|
||||
TSDOCKER_AUTO_CLEANUP=false
|
||||
TSDOCKER_CLEANUP_ON_START=false
|
||||
TSDOCKER_BUILDX_PRUNE_UNTIL=24h
|
||||
TSDOCKER_BUILDX_PRUNE_MAX_USED_SPACE=5gb
|
||||
|
||||
Global config is stored at ~/.git.zone/tsdocker/config.json
|
||||
and managed via the "config" command.
|
||||
@@ -102,10 +112,13 @@ export let run = () => {
|
||||
* Usage: tsdocker build [Dockerfile_patterns...] [--platform=linux/arm64] [--timeout=600]
|
||||
*/
|
||||
tsdockerCli.addCommand('build').subscribe(async argvArg => {
|
||||
let manager: TsDockerManager | undefined;
|
||||
let exitCode = 0;
|
||||
try {
|
||||
const config = await ConfigModule.run();
|
||||
const manager = new TsDockerManager(config);
|
||||
manager = new TsDockerManager(config);
|
||||
await manager.prepare(argvArg.context as string | undefined);
|
||||
await manager.cleanupStaleBuilders();
|
||||
|
||||
const buildOptions: IBuildCommandOptions = {};
|
||||
const patterns = argvArg._.slice(1) as string[];
|
||||
@@ -137,11 +150,15 @@ export let run = () => {
|
||||
}
|
||||
|
||||
await manager.build(buildOptions);
|
||||
await manager.cleanup();
|
||||
logger.log('success', 'Build completed successfully');
|
||||
} catch (err) {
|
||||
logger.log('error', `Build failed: ${(err as Error).message}`);
|
||||
process.exit(1);
|
||||
exitCode = 1;
|
||||
} finally {
|
||||
await manager?.cleanup();
|
||||
}
|
||||
if (exitCode !== 0) {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -150,10 +167,13 @@ export let run = () => {
|
||||
* Usage: tsdocker push [Dockerfile_patterns...] [--platform=linux/arm64] [--timeout=600] [--registry=url]
|
||||
*/
|
||||
tsdockerCli.addCommand('push').subscribe(async argvArg => {
|
||||
let manager: TsDockerManager | undefined;
|
||||
let exitCode = 0;
|
||||
try {
|
||||
const config = await ConfigModule.run();
|
||||
const manager = new TsDockerManager(config);
|
||||
manager = new TsDockerManager(config);
|
||||
await manager.prepare(argvArg.context as string | undefined);
|
||||
await manager.cleanupStaleBuilders();
|
||||
|
||||
// Login first
|
||||
await manager.login();
|
||||
@@ -202,11 +222,15 @@ export let run = () => {
|
||||
const registries = registryArg ? [registryArg] : undefined;
|
||||
|
||||
await manager.push(registries);
|
||||
await manager.cleanup();
|
||||
logger.log('success', 'Push completed successfully');
|
||||
} catch (err) {
|
||||
logger.log('error', `Push failed: ${(err as Error).message}`);
|
||||
process.exit(1);
|
||||
exitCode = 1;
|
||||
} finally {
|
||||
await manager?.cleanup();
|
||||
}
|
||||
if (exitCode !== 0) {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -240,10 +264,13 @@ export let run = () => {
|
||||
* Run container tests for all Dockerfiles
|
||||
*/
|
||||
tsdockerCli.addCommand('test').subscribe(async argvArg => {
|
||||
let manager: TsDockerManager | undefined;
|
||||
let exitCode = 0;
|
||||
try {
|
||||
const config = await ConfigModule.run();
|
||||
const manager = new TsDockerManager(config);
|
||||
manager = new TsDockerManager(config);
|
||||
await manager.prepare(argvArg.context as string | undefined);
|
||||
await manager.cleanupStaleBuilders();
|
||||
|
||||
// Build images first
|
||||
const buildOptions: IBuildCommandOptions = {};
|
||||
@@ -267,11 +294,15 @@ export let run = () => {
|
||||
|
||||
// Run tests
|
||||
await manager.test();
|
||||
await manager.cleanup();
|
||||
logger.log('success', 'Tests completed successfully');
|
||||
} catch (err) {
|
||||
logger.log('error', `Tests failed: ${(err as Error).message}`);
|
||||
process.exit(1);
|
||||
exitCode = 1;
|
||||
} finally {
|
||||
await manager?.cleanup();
|
||||
}
|
||||
if (exitCode !== 0) {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user