Skip to content

Commit

Permalink
feat(common): add containers.pruneDockerResources utility method
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
petermetz committed Mar 11, 2021
1 parent 9d9f805 commit d075168
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,28 @@ export class Containers {
await new Promise((resolve2) => setTimeout(resolve2, 1000));
} while (!reachable);
}

public static async pruneDockerResources(): Promise<void> {
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);
}
}
}

0 comments on commit d075168

Please sign in to comment.