summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
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)