From 1a82c9ce7d03fe025a6ca5f69af8105ba64e291a Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 6 May 2015 22:52:30 -0700 Subject: [PATCH] godep: update dockerclient. Signed-off-by: Andrea Luzzardi --- Godeps/Godeps.json | 2 +- .../github.com/samalba/dockerclient/README.md | 30 ++++++++-- .../samalba/dockerclient/dockerclient.go | 55 ++++++++++++++++--- .../samalba/dockerclient/interface.go | 1 + .../samalba/dockerclient/mockclient/mock.go | 5 ++ .../github.com/samalba/dockerclient/types.go | 16 ++++++ 6 files changed, 96 insertions(+), 13 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index f545fad6ed..1c20966395 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -60,7 +60,7 @@ }, { "ImportPath": "github.com/samalba/dockerclient", - "Rev": "8b9427265e82fddde577648b986fbe78d816b333" + "Rev": "5e5020b90dd4657c33d446356556481182d2d66b" }, { "ImportPath": "github.com/samuel/go-zookeeper/zk", diff --git a/Godeps/_workspace/src/github.com/samalba/dockerclient/README.md b/Godeps/_workspace/src/github.com/samalba/dockerclient/README.md index 26f2528959..046a9ce694 100644 --- a/Godeps/_workspace/src/github.com/samalba/dockerclient/README.md +++ b/Godeps/_workspace/src/github.com/samalba/dockerclient/README.md @@ -4,7 +4,9 @@ Docker client library in Go Well maintained docker client library. -Example: +# How to use it? + +Here is an example showing how to use it: ```go package main @@ -25,7 +27,7 @@ func main() { docker, _ := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil) // Get only running containers - containers, err := docker.ListContainers(false) + containers, err := docker.ListContainers(false, false, "") if err != nil { log.Fatal(err) } @@ -41,14 +43,19 @@ func main() { } // Create a container - containerConfig := &dockerclient.ContainerConfig{Image: "ubuntu:12.04", Cmd: []string{"bash"}} - containerId, err := docker.CreateContainer(containerConfig) + containerConfig := &dockerclient.ContainerConfig{ + Image: "ubuntu:14.04", + Cmd: []string{"bash"}, + AttachStdin: true, + Tty: true} + containerId, err := docker.CreateContainer(containerConfig, "foobar") if err != nil { log.Fatal(err) } // Start the container - err = docker.StartContainer(containerId) + hostConfig := &dockerclient.HostConfig{} + err = docker.StartContainer(containerId, hostConfig) if err != nil { log.Fatal(err) } @@ -58,6 +65,19 @@ func main() { // Listen to events docker.StartMonitorEvents(eventCallback, nil) + + // Hold the execution to look at the events coming time.Sleep(3600 * time.Second) } ``` + +# Maintainers + +List of people you can ping for feedback on Pull Requests or any questions. + +- [Sam Alba](https://github.com/samalba) +- [Michael Crosby](https://github.com/crosbymichael) +- [Andrea Luzzardi](https://github.com/aluzzardi) +- [Victor Vieux](https://github.com/vieux) +- [Evan Hazlett](https://github.com/ehazlett) +- [Donald Huang](https://github.com/donhcd) diff --git a/Godeps/_workspace/src/github.com/samalba/dockerclient/dockerclient.go b/Godeps/_workspace/src/github.com/samalba/dockerclient/dockerclient.go index 6fa614f37e..47213e4355 100644 --- a/Godeps/_workspace/src/github.com/samalba/dockerclient/dockerclient.go +++ b/Godeps/_workspace/src/github.com/samalba/dockerclient/dockerclient.go @@ -66,7 +66,25 @@ func NewDockerClientTimeout(daemonUrl string, tlsConfig *tls.Config, timeout tim func (client *DockerClient) doRequest(method string, path string, body []byte, headers map[string]string) ([]byte, error) { b := bytes.NewBuffer(body) - req, err := http.NewRequest(method, client.URL.String()+path, b) + + reader, err := client.doStreamRequest(method, path, b, headers) + if err != nil { + return nil, err + } + + defer reader.Close() + data, err := ioutil.ReadAll(reader) + if err != nil { + return nil, err + } + return data, nil +} + +func (client *DockerClient) doStreamRequest(method string, path string, in io.Reader, headers map[string]string) (io.ReadCloser, error) { + if (method == "POST" || method == "PUT") && in == nil { + in = bytes.NewReader(nil) + } + req, err := http.NewRequest(method, client.URL.String()+path, in) if err != nil { return nil, err } @@ -83,18 +101,19 @@ func (client *DockerClient) doRequest(method string, path string, body []byte, h } return nil, err } - defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } if resp.StatusCode == 404 { return nil, ErrNotFound } if resp.StatusCode >= 400 { + defer resp.Body.Close() + data, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } return nil, Error{StatusCode: resp.StatusCode, Status: resp.Status, msg: string(data)} } - return data, nil + + return resp.Body, nil } func (client *DockerClient) Info() (*Info, error) { @@ -464,3 +483,25 @@ func (client *DockerClient) RenameContainer(oldName string, newName string) erro _, err := client.doRequest("POST", uri, nil, nil) return err } + +func (client *DockerClient) ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) { + var fromSrc string + v := &url.Values{} + if source == "" { + fromSrc = "-" + } else { + fromSrc = source + } + + v.Set("fromSrc", fromSrc) + v.Set("repo", repository) + if tag != "" { + v.Set("tag", tag) + } + + var in io.Reader + if fromSrc == "-" { + in = tar + } + return client.doStreamRequest("POST", "/images/create?"+v.Encode(), in, nil) +} diff --git a/Godeps/_workspace/src/github.com/samalba/dockerclient/interface.go b/Godeps/_workspace/src/github.com/samalba/dockerclient/interface.go index f29a434230..0a7eb1e33b 100644 --- a/Godeps/_workspace/src/github.com/samalba/dockerclient/interface.go +++ b/Godeps/_workspace/src/github.com/samalba/dockerclient/interface.go @@ -34,4 +34,5 @@ type Client interface { PauseContainer(name string) error UnpauseContainer(name string) error RenameContainer(oldName string, newName string) error + ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) } diff --git a/Godeps/_workspace/src/github.com/samalba/dockerclient/mockclient/mock.go b/Godeps/_workspace/src/github.com/samalba/dockerclient/mockclient/mock.go index fe24329cb2..3b2f269d73 100644 --- a/Godeps/_workspace/src/github.com/samalba/dockerclient/mockclient/mock.go +++ b/Godeps/_workspace/src/github.com/samalba/dockerclient/mockclient/mock.go @@ -135,3 +135,8 @@ func (client *MockClient) RenameContainer(oldName string, newName string) error args := client.Mock.Called(oldName, newName) return args.Error(0) } + +func (client *MockClient) ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) { + args := client.Mock.Called(source, repository, tag, tar) + return args.Get(0).(io.ReadCloser), args.Error(1) +} diff --git a/Godeps/_workspace/src/github.com/samalba/dockerclient/types.go b/Godeps/_workspace/src/github.com/samalba/dockerclient/types.go index 3dbafc2843..14f69bd007 100644 --- a/Godeps/_workspace/src/github.com/samalba/dockerclient/types.go +++ b/Godeps/_workspace/src/github.com/samalba/dockerclient/types.go @@ -46,6 +46,8 @@ type HostConfig struct { SecurityOpt []string NetworkMode string RestartPolicy RestartPolicy + Ulimits []Ulimit + LogConfig LogConfig } type ExecConfig struct { @@ -88,8 +90,11 @@ type ContainerInfo struct { Running bool Paused bool Restarting bool + OOMKilled bool + Dead bool Pid int ExitCode int + Error string // contains last known error when starting the container StartedAt time.Time FinishedAt time.Time Ghost bool @@ -256,3 +261,14 @@ type Stats struct { MemoryStats MemoryStats `json:"memory_stats,omitempty"` BlkioStats BlkioStats `json:"blkio_stats,omitempty"` } + +type Ulimit struct { + Name string `json:"name"` + Soft uint64 `json:"soft"` + Hard uint64 `json:"hard"` +} + +type LogConfig struct { + Type string `json:"type"` + Config map[string]string `json:"config"` +}