Skip to content

Commit bc4bf61

Browse files
authored
#14: move image remove to defer (#19)
#14: move image remove to defer, set force remove option
1 parent c443772 commit bc4bf61

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pkg/action/env.container.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,17 @@ func (c *containerEnv) Execute(ctx context.Context, a *Action) (err error) {
243243
}
244244
}
245245

246-
if c.removeImg {
246+
defer func() {
247+
if !c.removeImg {
248+
return
249+
}
247250
err = c.imageRemove(ctx, a)
248251
if err != nil {
249252
log.Err("Image remove returned an error: %v", err)
250253
} else {
251254
cli.Println("Image %q was successfully removed", a.ActionDef().Image)
252255
}
253-
}
256+
}()
254257

255258
return err
256259
}
@@ -275,7 +278,7 @@ func (c *containerEnv) Close() error {
275278

276279
func (c *containerEnv) imageRemove(ctx context.Context, a *Action) error {
277280
_, err := c.driver.ImageRemove(ctx, a.ActionDef().Image, types.ImageRemoveOptions{
278-
Force: false,
281+
Force: true,
279282
PruneChildren: false,
280283
})
281284

pkg/action/env.container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func Test_ContainerExec_imageRemove(t *testing.T) {
252252
assert.NoError(err)
253253

254254
a := act.ActionDef()
255-
imgOpts := types.ImageRemoveOptions{Force: false, PruneChildren: false}
255+
imgOpts := types.ImageRemoveOptions{Force: true, PruneChildren: false}
256256
d.EXPECT().
257257
ImageRemove(ctx, a.Image, gomock.Eq(imgOpts)).
258258
Return(tt.ret...)

0 commit comments

Comments
 (0)