From b9cf46785b1120205be84ddc30b7901c47c8ce6c Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 30 May 2023 00:30:25 +0200 Subject: [PATCH] test: use trap to remove cache volume Signed-off-by: CrazyMax --- hack/test | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hack/test b/hack/test index 82fabf1a..5f8820aa 100755 --- a/hack/test +++ b/hack/test @@ -36,10 +36,9 @@ cacheVolume="buildx-test-cache" if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then docker create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod --name "$cacheVolume" alpine fi +if [ "$TEST_KEEP_CACHE" != "1" ]; then + trap 'docker rm -v $cacheVolume' EXIT +fi cid=$(docker create --rm -v /tmp $testReportsVol --volumes-from=$cacheVolume -e GITHUB_REF -e TEST_DOCKERD -e TEST_BUILDKIT_IMAGE -e SKIP_INTEGRATION_TESTS -e GOTESTSUM_FORMAT ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $iid gotestsum $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v}) docker start -a -i $cid - -if [ "$TEST_KEEP_CACHE" != "1" ]; then - docker rm -v $cacheVolume -fi