mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
8c9c9e137c
Signed-off-by: David Calavera <david.calavera@gmail.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package lib
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/runconfig"
|
|
)
|
|
|
|
// ContainerCommitOptions hods parameters to commit changes into a container.
|
|
type ContainerCommitOptions struct {
|
|
ContainerID string
|
|
RepositoryName string
|
|
Tag string
|
|
Comment string
|
|
Author string
|
|
Changes []string
|
|
Pause bool
|
|
JSONConfig string
|
|
}
|
|
|
|
// ContainerCommit applies changes into a container and creates a new tagged image.
|
|
func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
|
|
query := url.Values{}
|
|
query.Set("container", options.ContainerID)
|
|
query.Set("repo", options.RepositoryName)
|
|
query.Set("tag", options.Tag)
|
|
query.Set("comment", options.Comment)
|
|
query.Set("author", options.Author)
|
|
for _, change := range options.Changes {
|
|
query.Add("changes", change)
|
|
}
|
|
if options.Pause != true {
|
|
query.Set("pause", "0")
|
|
}
|
|
|
|
var (
|
|
config *runconfig.Config
|
|
response types.ContainerCommitResponse
|
|
)
|
|
|
|
if options.JSONConfig != "" {
|
|
config = &runconfig.Config{}
|
|
if err := json.Unmarshal([]byte(options.JSONConfig), config); err != nil {
|
|
return response, err
|
|
}
|
|
}
|
|
|
|
resp, err := cli.POST("/commit", query, config, nil)
|
|
if err != nil {
|
|
return response, err
|
|
}
|
|
defer ensureReaderClosed(resp)
|
|
|
|
if err := json.NewDecoder(resp.body).Decode(&response); err != nil {
|
|
return response, err
|
|
}
|
|
|
|
return response, nil
|
|
}
|