From 12e78155e1c119f0073a4c3e13486600897cadca Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Mon, 23 Mar 2020 09:12:04 -0500 Subject: apiv2 container commit for libpod add an endpoint for a libpod specific commit. add the abilility to define the format. also update documentation accordingly. Fixes: #5586 Signed-off-by: Brent Baude --- pkg/bindings/containers/commit.go | 49 +++++++++++++++++++++++++++++++++++++++ pkg/bindings/containers/types.go | 13 +++++++++++ pkg/bindings/test/pods_test.go | 3 +-- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 pkg/bindings/containers/commit.go (limited to 'pkg/bindings') diff --git a/pkg/bindings/containers/commit.go b/pkg/bindings/containers/commit.go new file mode 100644 index 000000000..12c25f842 --- /dev/null +++ b/pkg/bindings/containers/commit.go @@ -0,0 +1,49 @@ +package containers + +import ( + "context" + "net/http" + "net/url" + "strconv" + + "github.com/containers/libpod/pkg/api/handlers" + "github.com/containers/libpod/pkg/bindings" +) + +// Commit creates a container image from a container. The container is defined by nameOrId. Use +// the CommitOptions for finer grain control on characteristics of the resulting image. +func Commit(ctx context.Context, nameOrId string, options CommitOptions) (handlers.IDResponse, error) { + id := handlers.IDResponse{} + conn, err := bindings.GetClient(ctx) + if err != nil { + return id, err + } + params := url.Values{} + params.Set("container", nameOrId) + if options.Author != nil { + params.Set("author", *options.Author) + } + for _, change := range options.Changes { + params.Set("changes", change) + } + if options.Comment != nil { + params.Set("comment", *options.Comment) + } + if options.Format != nil { + params.Set("format", *options.Format) + } + if options.Pause != nil { + params.Set("pause", strconv.FormatBool(*options.Pause)) + } + if options.Repo != nil { + params.Set("repo", *options.Repo) + } + if options.Tag != nil { + params.Set("tag", *options.Tag) + } + response, err := conn.DoRequest(nil, http.MethodPost, "/commit", params) + if err != nil { + return id, err + } + return id, response.Process(&id) +} diff --git a/pkg/bindings/containers/types.go b/pkg/bindings/containers/types.go index 87342f7ea..31daaf565 100644 --- a/pkg/bindings/containers/types.go +++ b/pkg/bindings/containers/types.go @@ -11,3 +11,16 @@ type LogOptions struct { Timestamps *bool Until *string } + +// CommitOptions describe details about the resulting commited +// image as defined by repo and tag. None of these options +// are required. +type CommitOptions struct { + Author *string + Changes []string + Comment *string + Format *string + Pause *bool + Repo *string + Tag *string +} diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go index 29cfcdbbc..e94048a9c 100644 --- a/pkg/bindings/test/pods_test.go +++ b/pkg/bindings/test/pods_test.go @@ -80,8 +80,7 @@ var _ = Describe("Podman pods", func() { // The test validates the list pod endpoint with passing filters as the params. It("List pods with filters", func() { var ( - newpod2 string = "newpod2" - trueFlag = true + newpod2 string = "newpod2" ) bt.Podcreate(&newpod2) _, err = bt.RunTopContainer(nil, &bindings.PTrue, &newpod) -- cgit v1.2.3-54-g00ecf