diff --git a/Makefile b/Makefile index 50ac87297..8c26bf937 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ COMPRESSION_FBS_GO_FILES=$(wildcard $(COMPRESSION_FBS_DIR)/zinfo/*.go) COMMIT=$(shell git rev-parse HEAD) STARGZ_BINARY?=/usr/local/bin/containerd-stargz-grpc +INTEG_TEST_CONTAINERS=$(strip $(shell docker ps -aqf name="soci-integration-*")) +SOCI_BASE_IMAGE_IDS=$(shell docker image ls -qf reference="*:soci_test") + CMD=soci-snapshotter-grpc soci CMD_BINARIES=$(addprefix $(OUTDIR)/,$(CMD)) @@ -52,7 +55,7 @@ CMD_BINARIES=$(addprefix $(OUTDIR)/,$(CMD)) GO_BENCHMARK_TESTS?=. .PHONY: all build check flatc add-ltag install uninstall tidy vendor clean \ - test integration release benchmarks build-benchmarks \ + clean-integration test integration release benchmarks build-benchmarks \ benchmarks-perf-test benchmarks-comparison-test all: build @@ -89,12 +92,28 @@ uninstall: @echo "$@" @rm -f $(addprefix $(CMD_DESTDIR)/bin/,$(notdir $(CMD_BINARIES))) -clean: +clean: clean-integration @echo "๐Ÿงน ... ๐Ÿ—‘๏ธ" @rm -rf $(OUTDIR) @rm -rf $(CURDIR)/release/ @echo "All clean!" +clean-integration: + @echo "๐Ÿงน Cleaning leftover integration test artifacts..." + + @echo "๐Ÿณ Cleaning Docker artifacts..." +ifneq ($(INTEG_TEST_CONTAINERS),) + docker stop $(INTEG_TEST_CONTAINERS) + docker rm $(INTEG_TEST_CONTAINERS) + docker network rm $(shell docker network ls -qf name="soci-integration-*") + docker image rm $(SOCI_BASE_IMAGE_IDS) + @echo "๐Ÿณ All SOCI containers, networks, and images cleaned!" +else + @echo "๐Ÿณ No leftover Docker artifacts." +endif + + @echo "All testing artifacts cleaned!" + tidy: @GO111MODULE=$(GO111MODULE_VALUE) go mod tidy @cd ./cmd ; GO111MODULE=$(GO111MODULE_VALUE) go mod tidy diff --git a/integration/util_test.go b/integration/util_test.go index 49995b5bf..e3d102c46 100644 --- a/integration/util_test.go +++ b/integration/util_test.go @@ -413,7 +413,7 @@ func withPlainHTTP() registryConfigOpt { func newRegistryConfig(opts ...registryConfigOpt) registryConfig { rc := registryConfig{ - host: fmt.Sprintf("registry-%s.test", xid.New().String()), + host: fmt.Sprintf("%s-registry-%s.test", compose.TestContainerBaseName, xid.New().String()), user: "dummyuser", pass: "dummypass", } diff --git a/util/dockershell/compose/compose.go b/util/dockershell/compose/compose.go index cd5e958b0..b03f0cac0 100644 --- a/util/dockershell/compose/compose.go +++ b/util/dockershell/compose/compose.go @@ -35,6 +35,7 @@ package compose import ( "bufio" "errors" + "fmt" "io" "os" "os/exec" @@ -45,6 +46,10 @@ import ( "github.com/rs/xid" ) +const ( + TestContainerBaseName string = "soci-integration" +) + // Supported checks if this pkg can run on the current system. func Supported() error { return exec.Command("docker", "--version").Run() @@ -133,7 +138,7 @@ func Up(dockerComposeYaml string, opts ...Option) (*Compose, error) { for _, o := range opts { o(&cOpts) } - tmpContext, err := os.MkdirTemp("", "compose"+xid.New().String()) + tmpContext, err := os.MkdirTemp("", fmt.Sprintf("%s-compose-%s", TestContainerBaseName, xid.New().String())) if err != nil { return nil, err }