From d0751681ec715fc20716fdc71fd0df00a01d0559 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Mon, 8 Mar 2021 17:10:34 -0800 Subject: [PATCH] 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 --- .../src/main/typescript/common/containers.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/cactus-test-tooling/src/main/typescript/common/containers.ts b/packages/cactus-test-tooling/src/main/typescript/common/containers.ts index b5d10c5edb..14827bb0af 100644 --- a/packages/cactus-test-tooling/src/main/typescript/common/containers.ts +++ b/packages/cactus-test-tooling/src/main/typescript/common/containers.ts @@ -373,4 +373,28 @@ export class Containers { await new Promise((resolve2) => setTimeout(resolve2, 1000)); } while (!reachable); } + + public static async pruneDockerResources(): Promise { + const docker = new Dockerode(); + try { + await docker.pruneContainers(); + } catch (ex) { + console.warn(`Failed to prune docker containers: `, ex); + } + try { + await docker.pruneVolumes(); + } catch (ex) { + console.warn(`Failed to prune docker volumes: `, ex); + } + try { + await docker.pruneImages(); + } catch (ex) { + console.warn(`Failed to prune docker images: `, ex); + } + try { + await docker.pruneNetworks(); + } catch (ex) { + console.warn(`Failed to prune docker networks: `, ex); + } + } }