diff --git a/pkg/buildah/common.go b/pkg/buildah/common.go index 331533e190..d13d4df0e3 100644 --- a/pkg/buildah/common.go +++ b/pkg/buildah/common.go @@ -57,6 +57,10 @@ type RunCommandOpts struct { Mounts []specs.Mount } +type RmOpts struct { + CommonOpts +} + type RmiOpts struct { CommonOpts Force bool @@ -84,6 +88,7 @@ type Buildah interface { FromCommand(ctx context.Context, container string, image string, opts FromCommandOpts) (string, error) Pull(ctx context.Context, ref string, opts PullOpts) error Inspect(ctx context.Context, ref string) (*thirdparty.BuilderInfo, error) + Rm(ctx context.Context, ref string, opts RmOpts) error Rmi(ctx context.Context, ref string, opts RmiOpts) error Mount(ctx context.Context, container string, opts MountOpts) (string, error) Umount(ctx context.Context, container string, opts UmountOpts) error diff --git a/pkg/buildah/docker_with_fuse.go b/pkg/buildah/docker_with_fuse.go index 6bba3569b0..c44a1753d4 100644 --- a/pkg/buildah/docker_with_fuse.go +++ b/pkg/buildah/docker_with_fuse.go @@ -164,6 +164,11 @@ func (b *DockerWithFuseBuildah) Pull(ctx context.Context, ref string, opts PullO return err } +func (b *DockerWithFuseBuildah) Rm(ctx context.Context, ref string, opts RmOpts) error { + _, _, err := b.runBuildah(ctx, []string{}, []string{"rm", ref}, opts.LogWriter) + return err +} + func (b *DockerWithFuseBuildah) Rmi(ctx context.Context, ref string, opts RmiOpts) error { args := []string{"rmi"} if opts.Force { diff --git a/pkg/buildah/native_linux.go b/pkg/buildah/native_linux.go index 1b61ccc765..a52fcb3484 100644 --- a/pkg/buildah/native_linux.go +++ b/pkg/buildah/native_linux.go @@ -275,6 +275,15 @@ func (b *NativeBuildah) Pull(ctx context.Context, ref string, opts PullOpts) err return nil } +func (b *NativeBuildah) Rm(ctx context.Context, ref string, opts RmOpts) error { + builder, err := b.getBuilderFromContainer(ctx, ref) + if err != nil { + return fmt.Errorf("error getting builder: %w", err) + } + + return builder.Delete() +} + func (b *NativeBuildah) Rmi(ctx context.Context, ref string, opts RmiOpts) error { _, rmiErrors := b.Runtime.RemoveImages(ctx, []string{ref}, &libimage.RemoveImagesOptions{ Filters: []string{"readonly=false", "intermediate=false", "dangling=true"},