Skip to content

Commit

Permalink
Merge pull request #4308 from werf/refactor-buildah-add-rm-method
Browse files Browse the repository at this point in the history
refactor(buildah): add Rm method
  • Loading branch information
ilya-lesikov committed Mar 30, 2022
2 parents 290ac48 + af44cdd commit 6a023f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/buildah/common.go
Expand Up @@ -57,6 +57,10 @@ type RunCommandOpts struct {
Mounts []specs.Mount
}

type RmOpts struct {
CommonOpts
}

type RmiOpts struct {
CommonOpts
Force bool
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/buildah/docker_with_fuse.go
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/buildah/native_linux.go
Expand Up @@ -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"},
Expand Down

0 comments on commit 6a023f5

Please sign in to comment.