Skip to content

Commit 1142aec

Browse files
committed
Add testing suite cleanup to Makefile
Signed-off-by: David Son <[email protected]>
1 parent 2924990 commit 1142aec

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ COMPRESSION_FBS_GO_FILES=$(wildcard $(COMPRESSION_FBS_DIR)/zinfo/*.go)
4545
COMMIT=$(shell git rev-parse HEAD)
4646
STARGZ_BINARY?=/usr/local/bin/containerd-stargz-grpc
4747

48+
INTEG_TEST_CONTAINERS=$(strip $(shell docker ps -aqf name="soci-integration-*"))
49+
SOCI_BASE_IMAGE_IDS=$(shell docker image ls -qf reference="*:soci_test")
50+
4851
CMD=soci-snapshotter-grpc soci
4952

5053
CMD_BINARIES=$(addprefix $(OUTDIR)/,$(CMD))
5154

5255
GO_BENCHMARK_TESTS?=.
5356

5457
.PHONY: all build check flatc add-ltag install uninstall tidy vendor clean \
55-
test integration release benchmarks build-benchmarks \
58+
clean-integration test integration release benchmarks build-benchmarks \
5659
benchmarks-perf-test benchmarks-comparison-test
5760

5861
all: build
@@ -89,12 +92,28 @@ uninstall:
8992
@echo "$@"
9093
@rm -f $(addprefix $(CMD_DESTDIR)/bin/,$(notdir $(CMD_BINARIES)))
9194

92-
clean:
95+
clean: clean-integration
9396
@echo "🧹 ... 🗑️"
9497
@rm -rf $(OUTDIR)
9598
@rm -rf $(CURDIR)/release/
9699
@echo "All clean!"
97100

101+
clean-integration:
102+
@echo "🧹 Cleaning leftover integration test artifacts..."
103+
104+
@echo "🐳 Cleaning Docker artifacts..."
105+
ifneq ($(INTEG_TEST_CONTAINERS),)
106+
docker stop $(INTEG_TEST_CONTAINERS)
107+
docker rm $(INTEG_TEST_CONTAINERS)
108+
docker network rm $(shell docker network ls -qf name="soci-integration-*")
109+
docker image rm $(SOCI_BASE_IMAGE_IDS)
110+
@echo "🐳 All SOCI containers, networks, and images cleaned!"
111+
else
112+
@echo "🐳 No leftover Docker artifacts."
113+
endif
114+
115+
@echo "All testing artifacts cleaned!"
116+
98117
tidy:
99118
@GO111MODULE=$(GO111MODULE_VALUE) go mod tidy
100119
@cd ./cmd ; GO111MODULE=$(GO111MODULE_VALUE) go mod tidy

integration/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func withPlainHTTP() registryConfigOpt {
413413

414414
func newRegistryConfig(opts ...registryConfigOpt) registryConfig {
415415
rc := registryConfig{
416-
host: fmt.Sprintf("registry-%s.test", xid.New().String()),
416+
host: fmt.Sprintf("%s-registry-%s.test", compose.TestContainerBaseName, xid.New().String()),
417417
user: "dummyuser",
418418
pass: "dummypass",
419419
}

util/dockershell/compose/compose.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ package compose
3535
import (
3636
"bufio"
3737
"errors"
38+
"fmt"
3839
"io"
3940
"os"
4041
"os/exec"
@@ -45,6 +46,10 @@ import (
4546
"github.com/rs/xid"
4647
)
4748

49+
const (
50+
TestContainerBaseName string = "soci-integration"
51+
)
52+
4853
// Supported checks if this pkg can run on the current system.
4954
func Supported() error {
5055
return exec.Command("docker", "--version").Run()
@@ -133,7 +138,7 @@ func Up(dockerComposeYaml string, opts ...Option) (*Compose, error) {
133138
for _, o := range opts {
134139
o(&cOpts)
135140
}
136-
tmpContext, err := os.MkdirTemp("", "compose"+xid.New().String())
141+
tmpContext, err := os.MkdirTemp("", fmt.Sprintf("%s-compose-%s", TestContainerBaseName, xid.New().String()))
137142
if err != nil {
138143
return nil, err
139144
}

0 commit comments

Comments
 (0)