diff options
author | Qi Wang <qiwan@redhat.com> | 2018-08-15 14:29:03 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-08-16 15:35:28 +0000 |
commit | 1003df344424dc3b2bb7f957818359105dbfe4be (patch) | |
tree | fd9cae2f42037f5bc2ed5927ad78fea6ae5f8fac | |
parent | fee9f180fe74b99b408c3c26be12ab25160e3ff1 (diff) | |
download | podman-1003df344424dc3b2bb7f957818359105dbfe4be.tar.gz podman-1003df344424dc3b2bb7f957818359105dbfe4be.tar.bz2 podman-1003df344424dc3b2bb7f957818359105dbfe4be.zip |
Suport format param for varlink Commit
We need to pass the image format OCI or docker in the varlink commit command.
Signed-off-by: Qi Wang <qiwan@redhat.com>
Closes: #1281
Approved by: mheon
-rw-r--r-- | cmd/podman/varlink/io.podman.varlink | 2 | ||||
-rw-r--r-- | pkg/varlinkapi/images.go | 31 |
2 files changed, 21 insertions, 12 deletions
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink index 336600b2f..2cc381c5a 100644 --- a/cmd/podman/varlink/io.podman.varlink +++ b/cmd/podman/varlink/io.podman.varlink @@ -605,7 +605,7 @@ method DeleteUnusedImages() -> (images: []string) # container while it is being committed, pass a _true_ bool for the pause argument. If the container cannot # be found by the ID or name provided, a (ContainerNotFound)[#ContainerNotFound] error will be returned; otherwise, # the resulting image's ID will be returned as a string. -method Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool) -> (image: string) +method Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool, manifestType: string) -> (image: string) # ImportImage imports an image from a source (like tarball) into local storage. The image can have additional # descriptions added to it using the message and changes options. See also [ExportImage](ExportImage). diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index da19483b3..ae727d7ad 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -10,6 +10,7 @@ import ( "time" "github.com/containers/image/docker" + "github.com/containers/image/manifest" "github.com/containers/image/types" "github.com/docker/go-units" "github.com/opencontainers/image-spec/specs-go/v1" @@ -126,18 +127,17 @@ func (i *LibpodAPI) BuildImage(call iopodman.VarlinkCall, config iopodman.BuildI if config.Pull_always { pullPolicy = imagebuildah.PullAlways } - - format := "oci" + manifestType := "oci" if config.Image_format != "" { - format = config.Image_format + manifestType = config.Image_format } - if strings.HasPrefix(format, "oci") { - format = imagebuildah.OCIv1ImageFormat - } else if strings.HasPrefix(format, "docker") { - format = imagebuildah.Dockerv2ImageFormat + if strings.HasPrefix(manifestType, "oci") { + manifestType = imagebuildah.OCIv1ImageFormat + } else if strings.HasPrefix(manifestType, "docker") { + manifestType = imagebuildah.Dockerv2ImageFormat } else { - return call.ReplyErrorOccurred(fmt.Sprintf("unrecognized image type %q", format)) + return call.ReplyErrorOccurred(fmt.Sprintf("unrecognized image type %q", manifestType)) } if config.Memory != "" { @@ -187,7 +187,7 @@ func (i *LibpodAPI) BuildImage(call iopodman.VarlinkCall, config iopodman.BuildI AdditionalTags: config.Tags, //Runtime: runtime. //RuntimeArgs: , - OutputFormat: format, + OutputFormat: manifestType, SystemContext: &systemContext, CommonBuildOpts: commonOpts, Squash: config.Squash, @@ -413,17 +413,26 @@ func (i *LibpodAPI) DeleteUnusedImages(call iopodman.VarlinkCall) error { } // Commit ... -func (i *LibpodAPI) Commit(call iopodman.VarlinkCall, name, imageName string, changes []string, author, message string, pause bool) error { +func (i *LibpodAPI) Commit(call iopodman.VarlinkCall, name, imageName string, changes []string, author, message string, pause bool, manifestType string) error { ctr, err := i.Runtime.LookupContainer(name) if err != nil { return call.ReplyContainerNotFound(name) } sc := image.GetSystemContext(i.Runtime.GetConfig().SignaturePolicyPath, "", false) + var mimeType string + switch manifestType { + case "oci", "": + mimeType = buildah.OCIv1ImageManifest + case "docker": + mimeType = manifest.DockerV2Schema2MediaType + default: + return call.ReplyErrorOccurred(fmt.Sprintf("unrecognized image format %q", manifestType)) + } coptions := buildah.CommitOptions{ SignaturePolicyPath: i.Runtime.GetConfig().SignaturePolicyPath, ReportWriter: nil, SystemContext: sc, - PreferredManifestType: buildah.OCIv1ImageManifest, + PreferredManifestType: mimeType, } options := libpod.ContainerCommitOptions{ CommitOptions: coptions, |