Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Support the Commit API #148

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions dockerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,30 @@ func (client *DockerClient) BuildImage(image *BuildImage) (io.ReadCloser, error)
uri := fmt.Sprintf("/%s/build?%s", APIVersion, v.Encode())
return client.doStreamRequest("POST", uri, image.Context, headers)
}

func (client *DockerClient) Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error) {
config, err := json.Marshal(c)
if err != nil {
return "", err
}

v := url.Values{}
v.Set("container", id)
v.Set("repo", repo)
v.Set("tag", tag)
v.Set("comment", comment)
v.Set("author", author)

uri := fmt.Sprintf("/%s/commit?%s", APIVersion, v.Encode())
data, err := client.doRequest("POST", uri, config, nil)
if err != nil {
return "", err
}

var img Image
if err := json.Unmarshal(data, &img); err != nil {
return "", err
}

return img.Id, nil
}
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ type Client interface {
RenameContainer(oldName string, newName string) error
ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error)
BuildImage(image *BuildImage) (io.ReadCloser, error)
Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error)
}
5 changes: 5 additions & 0 deletions mockclient/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,8 @@ func (client *MockClient) BuildImage(image *dockerclient.BuildImage) (io.ReadClo
args := client.Mock.Called(image)
return args.Get(0).(io.ReadCloser), args.Error(1)
}

func (client *MockClient) Commit(id string, c *ContainerConfig, repo, tag, comment, author string) (string, error) {
args := client.Mock.Called(id, c, repo, tag, comment, author)
return args.Strings(0), args.Error(1)
}