Add make clean support to remove the containers from the local docker
registry.
make clean-<image_name> must be called to remove an image:
make clean-yocto/kirkstone-qemuarm: remove yocto kirkstone for qemuarm
image
Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
Changes in v5:
- remove cleaning of all images using make clean
Changes in v4:
- also generate clean rule for CONTAINERS_EXTRA
Changes in v3:
- none
Changes in v2:
- none
Changes in v1:
- patch added
---
automation/build/Makefile | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/automation/build/Makefile b/automation/build/Makefile
index 72a5335baec1..4cbb1365f94e 100644
--- a/automation/build/Makefile
+++ b/automation/build/Makefile
@@ -28,3 +28,13 @@ all: $(CONTAINERS)
clean:
rm -f yocto/*.dockerfiles
+define CLEAN_RULE
+.PHONY: clean-$(1)
+clean-$(1):
+ifneq ($$(shell docker image ls -q $(REGISTRY)/$(subst /,:,$(1))),)
+ docker image rm $(REGISTRY)/$(subst /,:,$(1))
+endif
+
+endef
+
+$(eval $(foreach img,$(CONTAINERS) $(CONTAINERS_EXTRA),$(call CLEAN_RULE,$(img))))
--
2.25.1
On Wed, Nov 30, 2022 at 12:15:08PM +0000, Bertrand Marquis wrote:
> --- a/automation/build/Makefile
> +++ b/automation/build/Makefile
> @@ -28,3 +28,13 @@ all: $(CONTAINERS)
> clean:
> rm -f yocto/*.dockerfiles
>
> +define CLEAN_RULE
> +.PHONY: clean-$(1)
> +clean-$(1):
> +ifneq ($$(shell docker image ls -q $(REGISTRY)/$(subst /,:,$(1))),)
Please, don't use "ifneq" in a rule's recipe, especially when running a
shell command. That shell command is evaluated every time make parse the
makefile, so we are going to run `docker image ls` 23 times!
Just write the call to `docker image ls` and evaluate the result in
shell. I guess something like:
[ "$(docker image ls -q ...)" ] && docker image rm ...
Cheers,
--
Anthony PERARD
Hi Anthony, > On 30 Nov 2022, at 15:48, Anthony PERARD <anthony.perard@citrix.com> wrote: > > On Wed, Nov 30, 2022 at 12:15:08PM +0000, Bertrand Marquis wrote: >> --- a/automation/build/Makefile >> +++ b/automation/build/Makefile >> @@ -28,3 +28,13 @@ all: $(CONTAINERS) >> clean: >> rm -f yocto/*.dockerfiles >> >> +define CLEAN_RULE >> +.PHONY: clean-$(1) >> +clean-$(1): >> +ifneq ($$(shell docker image ls -q $(REGISTRY)/$(subst /,:,$(1))),) > > Please, don't use "ifneq" in a rule's recipe, especially when running a > shell command. That shell command is evaluated every time make parse the > makefile, so we are going to run `docker image ls` 23 times! > > Just write the call to `docker image ls` and evaluate the result in > shell. I guess something like: > [ "$(docker image ls -q ...)" ] && docker image rm ... Very good point, I will fix that in v6. Cheers Bertrand > > > Cheers, > > -- > Anthony PERARD
Hi Bertrand, On 30/11/2022 13:15, Bertrand Marquis wrote: > > > Add make clean support to remove the containers from the local docker > registry. > make clean-<image_name> must be called to remove an image: > make clean-yocto/kirkstone-qemuarm: remove yocto kirkstone for qemuarm > image > > Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com> Reviewed-by: Michal Orzel <michal.orzel@amd.com> ~Michal
© 2016 - 2026 Red Hat, Inc.