diff mbox series

[v2,3/3] automation: Add a clean rule for containers

Message ID 357fcb93114840125a450acc9cf3ff7aa138a7bc.1665561024.git.bertrand.marquis@arm.com (mailing list archive)
State Superseded
Headers show
Series Yocto Gitlab CI | expand

Commit Message

Bertrand Marquis Oct. 12, 2022, 8:02 a.m. UTC
Add make clean support to remove the containers from the local docker
registry:
- make clean: remove all images
- clean-yocto/kirkstone-qemuarm: remove yocto kirkstone for qemuarm
image

Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
Changes in v2:
- none
Changes in v1:
- patch added
---
 automation/build/Makefile | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/automation/build/Makefile b/automation/build/Makefile
index b0dc68f00b70..9fbb49c8717e 100644
--- a/automation/build/Makefile
+++ b/automation/build/Makefile
@@ -4,6 +4,17 @@  REGISTRY := registry.gitlab.com/xen-project/xen
 CONTAINERS = $(subst .dockerfile,,$(wildcard */*.dockerfile))
 DOCKER_CMD ?= docker
 
+define CLEAN_RULE
+.PHONY: clean-$(1)
+clean-$(1):
+ifneq ($$(shell docker image ls -q $(REGISTRY)/$(subst /,:,$(1))),)
+	docker image rm $(REGISTRY)/$(subst /,:,$(1))
+endif
+
+clean: clean-$(1)
+
+endef
+
 help:
 	@echo "Builds containers for building Xen based on different distros"
 	@echo "To build one run 'make DISTRO/VERSION'. Available containers:"
@@ -18,5 +29,9 @@  help:
 
 $(subst .dockerfile,,$(wildcard yocto/kirkstone-*)): yocto/kirkstone
 
-.PHONY: all
+.PHONY: all clean
 all: $(CONTAINERS)
+
+clean:
+
+$(eval $(foreach img,$(CONTAINERS),$(call CLEAN_RULE,$(img))))