libcnb-test: Clean up Docker volumes after each test #741
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using
pack build
, by default Pack will create two Docker volumes for caching - one for the build layer cache, and the other for the launch layer cache. Pack bases the names for these volumes on the app image name, so that the next time a build is performed with the same app image name, the associated cache is used for that rebuild.When libcnb-test runs tests, it intentionally uses a random Docker image name for each new test, and then tears down the image and any associated containers after the tests.
However, until now the Docker volumes automatically created by Pack were not being removed, which can cause issues when running the tests locally, since the Docker VM can run out of disk space - as seen in #570. The leftover volumes can also be seen in the tests log output added in #740.
Pack doesn't currently offer a "clean up the volumes associated with this app name" feature, so we have to remove these volumes manually. To do so we need the volume name - which we achieve by generating a name ourselves, and passing it to
pack build
using the--cache
options, so Pack uses our volume name instead of generating its own automatic volume name.Since we're now cleaning up not only images but volumes too, I've refactored the way resources are cleaned up, to reduce the amount of duplication (since otherwise we'd need to handle the "still clean up for expected failures" case for volumes too). This new implementation also solves #735 and #736.
Fixes #570.
Fixes #735.
Fixes #736.
GUS-W-13195631.
GUS-W-14503186.
GUS-W-14503192.