From 4f8a7385e46abe3004d7a40a859fd761fb306d79 Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 13 Dec 2023 16:30:57 +0300 Subject: [PATCH 1/2] #14: move image remove to defer --- pkg/action/env.container.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/action/env.container.go b/pkg/action/env.container.go index 6605384..9400259 100644 --- a/pkg/action/env.container.go +++ b/pkg/action/env.container.go @@ -239,14 +239,17 @@ func (c *containerEnv) Execute(ctx context.Context, a *Action) (err error) { } } - if c.removeImg { + defer func() { + if !c.removeImg { + return + } err = c.imageRemove(ctx, a) if err != nil { log.Err("Image remove returned an error: %v", err) } else { cli.Println("Image %q was successfully removed", a.ActionDef().Image) } - } + }() return nil } From 534e78a183fcda04e6f9d4a79b0839f020b3d02c Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 13 Dec 2023 17:00:05 +0300 Subject: [PATCH 2/2] #14: set force remove option --- pkg/action/env.container.go | 2 +- pkg/action/env.container_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/action/env.container.go b/pkg/action/env.container.go index 9400259..558a8b7 100644 --- a/pkg/action/env.container.go +++ b/pkg/action/env.container.go @@ -274,7 +274,7 @@ func (c *containerEnv) Close() error { func (c *containerEnv) imageRemove(ctx context.Context, a *Action) error { _, err := c.driver.ImageRemove(ctx, a.ActionDef().Image, types.ImageRemoveOptions{ - Force: false, + Force: true, PruneChildren: false, }) diff --git a/pkg/action/env.container_test.go b/pkg/action/env.container_test.go index 6f4eb56..170fe9c 100644 --- a/pkg/action/env.container_test.go +++ b/pkg/action/env.container_test.go @@ -252,7 +252,7 @@ func Test_ContainerExec_imageRemove(t *testing.T) { assert.NoError(err) a := act.ActionDef() - imgOpts := types.ImageRemoveOptions{Force: false, PruneChildren: false} + imgOpts := types.ImageRemoveOptions{Force: true, PruneChildren: false} d.EXPECT(). ImageRemove(ctx, a.Image, gomock.Eq(imgOpts)). Return(tt.ret...)