Skip to content

Commit

Permalink
Merge pull request #4310 from werf/refactor-buildah-commit-optional-i…
Browse files Browse the repository at this point in the history
…mage

refactor(buildah): image should be optional for Commit()
  • Loading branch information
ilya-lesikov committed Mar 30, 2022
2 parents 4a395b5 + aa48597 commit 290ac48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/buildah/common.go
Expand Up @@ -64,6 +64,7 @@ type RmiOpts struct {

type CommitOpts struct {
CommonOpts
Image string
}

type (
Expand All @@ -86,7 +87,7 @@ type Buildah interface {
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
Commit(ctx context.Context, container, image string, opts CommitOpts) (string, error)
Commit(ctx context.Context, container string, opts CommitOpts) (string, error)
}

type Mode string
Expand Down
9 changes: 7 additions & 2 deletions pkg/buildah/docker_with_fuse.go
Expand Up @@ -175,11 +175,16 @@ func (b *DockerWithFuseBuildah) Rmi(ctx context.Context, ref string, opts RmiOpt
return err
}

func (b *DockerWithFuseBuildah) Commit(ctx context.Context, container, image string, opts CommitOpts) (string, error) {
func (b *DockerWithFuseBuildah) Commit(ctx context.Context, container string, opts CommitOpts) (string, error) {
args := []string{
"commit", "--quiet", "--format", "docker", "--signature-policy", b.SignaturePolicyPath,
fmt.Sprintf("--tls-verify=%s", strconv.FormatBool(!b.Insecure)), container, image,
fmt.Sprintf("--tls-verify=%s", strconv.FormatBool(!b.Insecure)), container,
}

if opts.Image != "" {
args = append(args, opts.Image)
}

imgID, _, err := b.runBuildah(ctx, []string{}, args, opts.LogWriter)
return imgID, err
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/buildah/native_linux.go
Expand Up @@ -285,15 +285,18 @@ func (b *NativeBuildah) Rmi(ctx context.Context, ref string, opts RmiOpts) error
return multierror.Append(multiErr, rmiErrors...).ErrorOrNil()
}

func (b *NativeBuildah) Commit(ctx context.Context, container, image string, opts CommitOpts) (string, error) {
func (b *NativeBuildah) Commit(ctx context.Context, container string, opts CommitOpts) (string, error) {
builder, err := b.getBuilderFromContainer(ctx, container)
if err != nil {
return "", fmt.Errorf("error getting builder: %w", err)
}

imageRef, err := alltransports.ParseImageName(image)
if err != nil {
return "", fmt.Errorf("error parsing image name: %w", err)
var imageRef imgtypes.ImageReference
if opts.Image != "" {
imageRef, err = alltransports.ParseImageName(opts.Image)
if err != nil {
return "", fmt.Errorf("error parsing image name: %w", err)
}
}

imgID, _, _, err := builder.Commit(ctx, imageRef, buildah.CommitOptions{
Expand Down

0 comments on commit 290ac48

Please sign in to comment.