Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcnb-test: Test container, volume and image cleanup in CI #740

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Nov 16, 2023

At the end of each test libcnb-test is meant to clean up any Docker resources that were created during the test. However, this functionality currently isn't tested, and we've found several cases where cleanup wasn't occurring as expected:

We could try and add a Rust integration test or two to check that cleanup works in the common case, however, as seen by the issues above, it's often in the edge cases where resource cleanup wasn't working. In addition, testing cleanup during an individual test is hard, since other tests will be running at the same time, so we'd have to check for individual image or container names, which would miss cases like #570.

As such, it's much easier for us to instead just check that there are zero unexpected resources left behind at the end of the existing entire libcnb-test test suite.

For now, two of the checks don't cause CI to fail, since the fixes for the cleanup implementations have not yet landed.

GUS-W-14502524.

@edmorley edmorley self-assigned this Nov 16, 2023
@edmorley edmorley changed the title Test libcnb-test container, volume and image cleanup in CI libcnb-test: Test container, volume and image cleanup in CI Nov 16, 2023
@edmorley edmorley marked this pull request as ready for review November 16, 2023 11:37
@edmorley edmorley requested a review from a team as a code owner November 16, 2023 11:37
@edmorley edmorley force-pushed the edmorley/libcnb-test-cleanup-ci branch from 34a78e5 to 6cd5685 Compare November 16, 2023 11:39
At the end of each test libcnb-test is meant to clean up any Docker
resources that were created during the test. However, this functionality
currently isn't tested, and we've found several cases where cleanup
wasn't occurring as expected:
- #586
- #570
- #737

We could try and add a Rust integration test or two to check that
cleanup works in the common case, however, as seen by the issues
above, it's often in the edge cases where resource cleanup wasn't
working. In addition, testing cleanup during an individual test is hard,
since other tests will be running at the same time, so we'd have to
check for individual image or container names, which would miss
cases like #570.

As such, it's much easier for us to instead just check that there are
zero unexpected resources left behind at the end of the existing entire
libcnb-test test suite.

For now, two of the checks don't cause CI to fail, since the fixes for
the cleanup implementations have not yet landed.

GUS-W-14502524.
@edmorley edmorley force-pushed the edmorley/libcnb-test-cleanup-ci branch from 6cd5685 to 839b6fd Compare November 16, 2023 11:40
@edmorley edmorley enabled auto-merge (squash) November 16, 2023 11:40
@edmorley edmorley disabled auto-merge November 16, 2023 11:40
@edmorley edmorley enabled auto-merge (squash) November 16, 2023 11:40
@edmorley edmorley merged commit 9b105dd into main Nov 16, 2023
4 checks passed
@edmorley edmorley deleted the edmorley/libcnb-test-cleanup-ci branch November 16, 2023 11:54
edmorley added a commit that referenced this pull request Nov 17, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants