[PATCH v4 2/3] automation: Add a clean rule for containers

Bertrand Marquis posted 3 patches 3 years, 2 months ago
There is a newer version of this series
[PATCH v4 2/3] automation: Add a clean rule for containers
Posted by Bertrand Marquis 3 years, 2 months ago
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 v4:
- also generate clean rule for CONTAINERS_EXTRA
Changes in v3:
- none
Changes in v2:
- none
Changes in v1:
- patch added
---
 automation/build/Makefile | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/automation/build/Makefile b/automation/build/Makefile
index 72a5335baec1..5b5f10c63ea4 100644
--- a/automation/build/Makefile
+++ b/automation/build/Makefile
@@ -28,3 +28,15 @@ 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
+
+clean: clean-$(1)
+
+endef
+
+$(eval $(foreach img,$(CONTAINERS) $(CONTAINERS_EXTRA),$(call CLEAN_RULE,$(img))))
-- 
2.25.1
Re: [PATCH v4 2/3] automation: Add a clean rule for containers
Posted by Michal Orzel 3 years, 2 months ago
Hi Bertrand,

On 17/11/2022 10:39, Bertrand Marquis wrote:
> 
> 
> Add make clean support to remove the containers from the local docker
> registry:
I have to say that I am a bit scared of adding a clean rule.
make clean is something that can easily sneak into this directory and can
remove the yocto images that we had to spent several hours to build.
The accidental clean can have severe consequences :)

In any case, if we want to add such possibility I would stick to calling always:
make clean-<image>
and remove the option to call "make clean" to remove all the images.

~Michal
Re: [PATCH v4 2/3] automation: Add a clean rule for containers
Posted by Bertrand Marquis 3 years, 2 months ago
Hi Michal,

> On 18 Nov 2022, at 08:58, Michal Orzel <michal.orzel@amd.com> wrote:
> 
> Hi Bertrand,
> 
> On 17/11/2022 10:39, Bertrand Marquis wrote:
>> 
>> 
>> Add make clean support to remove the containers from the local docker
>> registry:
> I have to say that I am a bit scared of adding a clean rule.
> make clean is something that can easily sneak into this directory and can
> remove the yocto images that we had to spent several hours to build.
> The accidental clean can have severe consequences :)
> 
> In any case, if we want to add such possibility I would stick to calling always:
> make clean-<image>
> and remove the option to call "make clean" to remove all the images.

Make sense, I will remove those to be automatically called from make clean

Cheers
Bertrand

> 
> ~Michal