Skip to content

Commit d075168

Browse files
committed
feat(common): add containers.pruneDockerResources utility method
This method attempts (in a very resilient way) to free up docker resources by pruning first the containers, then the volumes, then the images and finally even the networks. It is NOT designed to be used on a local development machine since there it's usually preferred for the contributors to control how these things are done manually to ensure they do not prune anything that they don't wish to. What is this for then? It's been added specifically to be executed by integration tests that run in the CI environment where recently issues started popping up regarding the GitHub CI Action/Workflow VM having its disk full due to our usage of docker images (the AIO images are quite fat). So the idea is that tests can call this function before their own execution in an attempt to free up enough disk space for the upcoming tests to continue passing without having to bail out due to the disk being full. Signed-off-by: Peter Somogyvari <[email protected]>
1 parent 9d9f805 commit d075168

File tree

1 file changed

+24
-0
lines changed
  • packages/cactus-test-tooling/src/main/typescript/common

1 file changed

+24
-0
lines changed

packages/cactus-test-tooling/src/main/typescript/common/containers.ts

+24
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,28 @@ export class Containers {
373373
await new Promise((resolve2) => setTimeout(resolve2, 1000));
374374
} while (!reachable);
375375
}
376+
377+
public static async pruneDockerResources(): Promise<void> {
378+
const docker = new Dockerode();
379+
try {
380+
await docker.pruneContainers();
381+
} catch (ex) {
382+
console.warn(`Failed to prune docker containers: `, ex);
383+
}
384+
try {
385+
await docker.pruneVolumes();
386+
} catch (ex) {
387+
console.warn(`Failed to prune docker volumes: `, ex);
388+
}
389+
try {
390+
await docker.pruneImages();
391+
} catch (ex) {
392+
console.warn(`Failed to prune docker images: `, ex);
393+
}
394+
try {
395+
await docker.pruneNetworks();
396+
} catch (ex) {
397+
console.warn(`Failed to prune docker networks: `, ex);
398+
}
399+
}
376400
}

0 commit comments

Comments
 (0)