summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-03-23 09:12:04 -0500
committerBrent Baude <bbaude@redhat.com>2020-03-23 14:14:17 -0500
commit12e78155e1c119f0073a4c3e13486600897cadca (patch)
tree83f079048c6ca0507ff02089465464147e6ed3a1 /pkg/bindings
parent48b3143656bde2163025d43a8a9b2c88208ffee8 (diff)
downloadpodman-12e78155e1c119f0073a4c3e13486600897cadca.tar.gz
podman-12e78155e1c119f0073a4c3e13486600897cadca.tar.bz2
podman-12e78155e1c119f0073a4c3e13486600897cadca.zip
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 <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/commit.go49
-rw-r--r--pkg/bindings/containers/types.go13
-rw-r--r--pkg/bindings/test/pods_test.go3
3 files changed, 63 insertions, 2 deletions
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)