diff mbox series

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

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

Commit Message

Bertrand Marquis Nov. 17, 2022, 9:39 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 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(+)

Comments

Michal Orzel Nov. 18, 2022, 8:58 a.m. UTC | #1
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
Bertrand Marquis Nov. 18, 2022, 1:09 p.m. UTC | #2
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
diff mbox series

Patch

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))))