Skip to content

Commit 627d8ca

Browse files
committed
fix(tests): cleanup Docker volumes in smoke tests
Add explicit Docker volume cleanup to prevent disk space exhaustion in CI environments. Registry containers create persistent volumes that were not being removed, causing "No space left on device" errors in GitHub Actions. Changes: - Enhanced TestRegistry.Close() to inspect and remove associated volumes before container deletion - Added CleanupDockerVolumes() helper method to prune unused volumes across all tests - Updated all smoke tests (airgap, hello, desiredstate) to call volume cleanup in defer blocks The registry:2 image stores data in /var/lib/registry which creates Docker volumes. With multiple registries per test (airgap test creates 12), these volumes were accumulating and filling disk space. Signed-off-by: Kim Christensen <kimworking@gmail.com>
1 parent 59d6a26 commit 627d8ca

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

tests/smoke/airgap_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestAirgappedEnvironment(t *testing.T) {
5555
defer func() {
5656
test.CleanupBundleImages("mybuns")
5757
test.CleanupDanglingImages()
58+
test.CleanupDockerVolumes()
5859
}()
5960

6061
// Enable optimized build if requested

tests/smoke/desiredstate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func runDesiredStateTest(t *testing.T, enableOptimizedBuild bool) {
4545
test.CleanupBundleImages("mybuns")
4646
test.CleanupBundleImages("mydb")
4747
test.CleanupDanglingImages()
48+
test.CleanupDockerVolumes()
4849
}()
4950

5051
// Enable optimized build if requested

tests/smoke/hello_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func runHelloBundleTest(t *testing.T, enableOptimizedBuild bool) {
4545
test.CleanupBundleImages("mybuns")
4646
test.CleanupBundleImages("mydb")
4747
test.CleanupDanglingImages()
48+
test.CleanupDockerVolumes()
4849
}()
4950

5051
// Enable optimized build if requested

tests/tester/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,15 @@ func (t Tester) CleanupDockerBuildCache() {
282282
t.T.Logf("Warning: could not prune build cache: %v", err)
283283
}
284284
}
285+
286+
// CleanupDockerVolumes removes unused Docker volumes to free disk space.
287+
// This is an optional cleanup method that tests can call explicitly when disk space is a concern.
288+
func (t Tester) CleanupDockerVolumes() {
289+
t.T.Helper()
290+
t.T.Log("Cleaning up unused Docker volumes")
291+
292+
// Prune unused volumes
293+
if err := shx.RunE("docker", "volume", "prune", "-f"); err != nil {
294+
t.T.Logf("Warning: could not prune volumes: %v", err)
295+
}
296+
}

tests/tester/test_registry.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89

910
"github.com/stretchr/testify/assert"
@@ -47,16 +48,31 @@ func (t *TestRegistry) String() string {
4748
return fmt.Sprintf("%s:%s", t.hostname, t.port)
4849
}
4950

50-
// Close stops the registry.
51+
// Close stops the registry and removes its volumes.
5152
func (t *TestRegistry) Close() {
5253
// Only call close once
5354
if t.closed {
5455
return
5556
}
5657

58+
// Remove the container and its associated volumes
59+
// First get the volumes associated with this container
60+
volumes, _ := shx.OutputE("docker", "inspect", "-f", "{{ range .Mounts }}{{ .Name }} {{ end }}", t.containerID)
61+
62+
// Remove the container
5763
err := shx.RunE("docker", "rm", "-vf", t.containerID)
5864
t.closed = true
5965
assert.NoError(t.t, err)
66+
67+
// Clean up any volumes that were associated with the container
68+
// The -v flag on docker rm doesn't always remove volumes, especially named ones
69+
if volumes != "" {
70+
for _, vol := range strings.Fields(volumes) {
71+
if vol != "" {
72+
shx.RunE("docker", "volume", "rm", vol)
73+
}
74+
}
75+
}
6076
}
6177

6278
// StartTestRegistry runs an OCI registry in a container,

0 commit comments

Comments
 (0)