implement varlink commit

Signed-off-by: baude <bbaude@redhat.com>

Closes: #762
Approved by: baude
This commit is contained in:
baude
2018-05-11 12:33:47 -05:00
committed by Atomic Bot
parent 962fde3c6c
commit d870c25c01
5 changed files with 1344 additions and 1274 deletions

40
API.md
View File

@ -7,9 +7,9 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file
[func BuildImage() NotImplemented](#BuildImage)
[func CreateContainer() NotImplemented](#CreateContainer)
[func Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool) string](#Commit)
[func CreateFromContainer() NotImplemented](#CreateFromContainer)
[func CreateContainer() NotImplemented](#CreateContainer)
[func CreateImage() NotImplemented](#CreateImage)
@ -27,14 +27,14 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file
[func GetContainerStats(name: string) ContainerStats](#GetContainerStats)
[func GetInfo() PodmanInfo](#GetInfo)
[func GetVersion() Version](#GetVersion)
[func HistoryImage(name: string) ImageHistory](#HistoryImage)
[func ImportImage(source: string, reference: string, message: string, changes: []string) string](#ImportImage)
[func Info() PodmanInfo](#Info)
[func InspectContainer(name: string) string](#InspectContainer)
[func InspectImage(name: string) string](#InspectImage)
@ -134,16 +134,22 @@ This method has not be implemented yet.
method BuildImage() [NotImplemented](#NotImplemented)</div>
This function is not implemented yet.
### <a name="Commit"></a>func Commit
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method Commit(name: [string](https://godoc.org/builtin#string), image_name: [string](https://godoc.org/builtin#string), changes: [[]string](#[]string), author: [string](https://godoc.org/builtin#string), message: [string](https://godoc.org/builtin#string), pause: [bool](https://godoc.org/builtin#bool)) [string](https://godoc.org/builtin#string)</div>
Commit, creates an image from an existing container. It requires the name or
ID of the container as well as the resulting image name. Optionally, you can define an author and message
to be added to the resulting image. You can also define changes to the resulting image for the following
attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the
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.
### <a name="CreateContainer"></a>func CreateContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method CreateContainer() [NotImplemented](#NotImplemented)</div>
This method has not been implemented yet.
### <a name="CreateFromContainer"></a>func CreateFromContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method CreateFromContainer() [NotImplemented](#NotImplemented)</div>
This method is not implemented.
This method is not implemented yet.
### <a name="CreateImage"></a>func CreateImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -219,6 +225,12 @@ $ varlink call -m unix:/run/io.projectatomic.podman/io.projectatomic.podman.GetC
}
}
~~~
### <a name="GetInfo"></a>func GetInfo
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method GetInfo() [PodmanInfo](#PodmanInfo)</div>
GetInfo returns a [PodmanInfo](#PodmanInfo) struct that describes podman and its host such as storage stats,
build information of Podman, and system-wide registries.
### <a name="GetVersion"></a>func GetVersion
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -238,12 +250,6 @@ history is in the form of an array of ImageHistory structures. If the image can
method ImportImage(source: [string](https://godoc.org/builtin#string), reference: [string](https://godoc.org/builtin#string), message: [string](https://godoc.org/builtin#string), changes: [[]string](#[]string)) [string](https://godoc.org/builtin#string)</div>
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).
### <a name="Info"></a>func Info
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method Info() [PodmanInfo](#PodmanInfo)</div>
Info returns a [PodmanInfo](#PodmanInfo) struct that describes podman and its host such as storage stats,
build information of Podman, and system-wide registries.
### <a name="InspectContainer"></a>func InspectContainer
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
@ -576,7 +582,7 @@ name [string](https://godoc.org/builtin#string)
star_count [int](https://godoc.org/builtin#int)
### <a name="InfoGraphStatus"></a>type InfoGraphStatus
InfoGraphStatus describes the detailed status of the graphc
InfoGraphStatus describes the detailed status of the storage driver
backing_filesystem [string](https://godoc.org/builtin#string)

View File

@ -138,7 +138,7 @@ type InfoHost (
uptime: string
)
# InfoGraphStatus describes the detailed status of the graph
# InfoGraphStatus describes the detailed status of the storage driver
type InfoGraphStatus (
backing_filesystem: string,
native_overlay_diff: string,
@ -202,7 +202,7 @@ method ListContainers() -> (containers: []ListContainerData)
# See also [ListContainers](ListContainers) and [InspectContainer](InspectContainer).
method GetContainer(name: string) -> (container: ListContainerData)
# This method has not been implemented yet.
# This method is not implemented yet.
method CreateContainer() -> (notimplemented: NotImplemented)
# InspectContainer data takes a name or ID of a container returns the inspection
@ -391,8 +391,14 @@ method SearchImage(name: string, limit: int) -> (images: []ImageSearch)
# in a string array.
method DeleteUnusedImages() -> (images: []string)
# This method is not implemented.
method CreateFromContainer() -> (notimplemented: NotImplemented)
# Commit, creates an image from an existing container. It requires the name or
# ID of the container as well as the resulting image name. Optionally, you can define an author and message
# to be added to the resulting image. You can also define changes to the resulting image for the following
# attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the
# 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)
# 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).

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@ package libpod
import (
"context"
"fmt"
"strings"
is "github.com/containers/image/storage"
@ -145,6 +144,5 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
if err != nil {
return nil, err
}
fmt.Fprintf(commitOptions.ReportWriter, importBuilder.Comment())
return c.runtime.imageRuntime.NewFromLocal(id)
}

View File

@ -6,8 +6,10 @@ import (
"github.com/containers/image/docker"
"github.com/opencontainers/image-spec/specs-go/v1"
"github.com/projectatomic/buildah"
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink"
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
sysreg "github.com/projectatomic/libpod/pkg/registries"
"github.com/projectatomic/libpod/pkg/util"
@ -232,10 +234,36 @@ func (i *LibpodAPI) DeleteUnusedImages(call ioprojectatomicpodman.VarlinkCall) e
return call.ReplyDeleteUnusedImages(deletedImages)
}
// CreateFromContainer ...
// TODO This must wait until buildah is properly vendored into libpod
func (i *LibpodAPI) CreateFromContainer(call ioprojectatomicpodman.VarlinkCall) error {
return call.ReplyMethodNotImplemented("CreateFromContainer")
// Commit ...
func (i *LibpodAPI) Commit(call ioprojectatomicpodman.VarlinkCall, name, imageName string, changes []string, author, message string, pause bool) error {
runtime, err := libpodruntime.GetRuntime(i.Cli)
if err != nil {
return call.ReplyRuntimeError(err.Error())
}
ctr, err := runtime.LookupContainer(name)
if err != nil {
return call.ReplyContainerNotFound(name)
}
sc := image.GetSystemContext(runtime.GetConfig().SignaturePolicyPath, "", false)
coptions := buildah.CommitOptions{
SignaturePolicyPath: runtime.GetConfig().SignaturePolicyPath,
ReportWriter: nil,
SystemContext: sc,
PreferredManifestType: buildah.OCIv1ImageManifest,
}
options := libpod.ContainerCommitOptions{
CommitOptions: coptions,
Pause: pause,
Message: message,
Changes: changes,
Author: author,
}
newImage, err := ctr.Commit(getContext(), imageName, options)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
return call.ReplyCommit(newImage.ID())
}
// ImportImage imports an image from a tarball to the image store