mirror of https://github.com/docker/docs.git
Vendor engine-api with required arguments
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
172ca1ca8c
commit
9802d7d10f
|
@ -25,7 +25,7 @@ clone git golang.org/x/net 78cb2c067747f08b343f20614155233ab4ea2ad3 https://gith
|
||||||
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
|
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
|
||||||
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
||||||
clone git github.com/docker/go-connections v0.2.0
|
clone git github.com/docker/go-connections v0.2.0
|
||||||
clone git github.com/docker/engine-api 8924d6900370b4c7e7984be5adc61f50a80d7537
|
clone git github.com/docker/engine-api a6dca654f28f26b648115649f6382252ada81119
|
||||||
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
|
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
|
||||||
clone git github.com/imdario/mergo 0.2.1
|
clone git github.com/imdario/mergo 0.2.1
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,12 @@ func (cli *Client) ClientVersion() string {
|
||||||
return cli.version
|
return cli.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateClientVersion updates the version string associated with this
|
||||||
|
// instance of the Client.
|
||||||
|
func (cli *Client) UpdateClientVersion(v string) {
|
||||||
|
cli.version = v
|
||||||
|
}
|
||||||
|
|
||||||
// ParseHost verifies that the given host strings is valid.
|
// ParseHost verifies that the given host strings is valid.
|
||||||
func ParseHost(host string) (string, string, string, error) {
|
func ParseHost(host string) (string, string, string, error) {
|
||||||
protoAddrParts := strings.SplitN(host, "://", 2)
|
protoAddrParts := strings.SplitN(host, "://", 2)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// It returns a types.HijackedConnection with the hijacked connection
|
// It returns a types.HijackedConnection with the hijacked connection
|
||||||
// and the a reader to get output. It's up to the called to close
|
// and the a reader to get output. It's up to the called to close
|
||||||
// the hijacked connection by calling types.HijackedResponse.Close.
|
// the hijacked connection by calling types.HijackedResponse.Close.
|
||||||
func (cli *Client) ContainerAttach(ctx context.Context, options types.ContainerAttachOptions) (types.HijackedResponse, error) {
|
func (cli *Client) ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if options.Stream {
|
if options.Stream {
|
||||||
query.Set("stream", "1")
|
query.Set("stream", "1")
|
||||||
|
@ -30,5 +30,5 @@ func (cli *Client) ContainerAttach(ctx context.Context, options types.ContainerA
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := map[string][]string{"Content-Type": {"text/plain"}}
|
headers := map[string][]string{"Content-Type": {"text/plain"}}
|
||||||
return cli.postHijacked(ctx, "/containers/"+options.ContainerID+"/attach", query, nil, headers)
|
return cli.postHijacked(ctx, "/containers/"+container+"/attach", query, nil, headers)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,36 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
distreference "github.com/docker/distribution/reference"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
|
"github.com/docker/engine-api/types/reference"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerCommit applies changes into a container and creates a new tagged image.
|
// ContainerCommit applies changes into a container and creates a new tagged image.
|
||||||
func (cli *Client) ContainerCommit(ctx context.Context, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
|
func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
|
||||||
|
var repository, tag string
|
||||||
|
if options.Reference != "" {
|
||||||
|
distributionRef, err := distreference.ParseNamed(options.Reference)
|
||||||
|
if err != nil {
|
||||||
|
return types.ContainerCommitResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical {
|
||||||
|
return types.ContainerCommitResponse{}, errors.New("refusing to create a tag with a digest reference")
|
||||||
|
}
|
||||||
|
|
||||||
|
tag = reference.GetTagFromNamedRef(distributionRef)
|
||||||
|
repository = distributionRef.Name()
|
||||||
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("container", options.ContainerID)
|
query.Set("container", container)
|
||||||
query.Set("repo", options.RepositoryName)
|
query.Set("repo", repository)
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", tag)
|
||||||
query.Set("comment", options.Comment)
|
query.Set("comment", options.Comment)
|
||||||
query.Set("author", options.Author)
|
query.Set("author", options.Author)
|
||||||
for _, change := range options.Changes {
|
for _, change := range options.Changes {
|
||||||
|
|
|
@ -8,9 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerExecCreate creates a new exec configuration to run an exec process.
|
// ContainerExecCreate creates a new exec configuration to run an exec process.
|
||||||
func (cli *Client) ContainerExecCreate(ctx context.Context, config types.ExecConfig) (types.ContainerExecCreateResponse, error) {
|
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error) {
|
||||||
var response types.ContainerExecCreateResponse
|
var response types.ContainerExecCreateResponse
|
||||||
resp, err := cli.post(ctx, "/containers/"+config.Container+"/exec", nil, config, nil)
|
resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Filter.Len() > 0 {
|
if options.Filter.Len() > 0 {
|
||||||
filterJSON, err := filters.ToParam(options.Filter)
|
filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filter)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// ContainerLogs returns the logs generated by a container in an io.ReadCloser.
|
// ContainerLogs returns the logs generated by a container in an io.ReadCloser.
|
||||||
// It's up to the caller to close the stream.
|
// It's up to the caller to close the stream.
|
||||||
func (cli *Client) ContainerLogs(ctx context.Context, options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
func (cli *Client) ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if options.ShowStdout {
|
if options.ShowStdout {
|
||||||
query.Set("stdout", "1")
|
query.Set("stdout", "1")
|
||||||
|
@ -40,7 +40,7 @@ func (cli *Client) ContainerLogs(ctx context.Context, options types.ContainerLog
|
||||||
}
|
}
|
||||||
query.Set("tail", options.Tail)
|
query.Set("tail", options.Tail)
|
||||||
|
|
||||||
resp, err := cli.get(ctx, "/containers/"+options.ContainerID+"/logs", query, nil)
|
resp, err := cli.get(ctx, "/containers/"+container+"/logs", query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerRemove kills and removes a container from the docker host.
|
// ContainerRemove kills and removes a container from the docker host.
|
||||||
func (cli *Client) ContainerRemove(ctx context.Context, options types.ContainerRemoveOptions) error {
|
func (cli *Client) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if options.RemoveVolumes {
|
if options.RemoveVolumes {
|
||||||
query.Set("v", "1")
|
query.Set("v", "1")
|
||||||
|
@ -21,7 +21,7 @@ func (cli *Client) ContainerRemove(ctx context.Context, options types.ContainerR
|
||||||
query.Set("force", "1")
|
query.Set("force", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.delete(ctx, "/containers/"+options.ContainerID, query, nil)
|
resp, err := cli.delete(ctx, "/containers/"+containerID, query, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerResize changes the size of the tty for a container.
|
// ContainerResize changes the size of the tty for a container.
|
||||||
func (cli *Client) ContainerResize(ctx context.Context, options types.ResizeOptions) error {
|
func (cli *Client) ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error {
|
||||||
return cli.resize(ctx, "/containers/"+options.ID, options.Height, options.Width)
|
return cli.resize(ctx, "/containers/"+containerID, options.Height, options.Width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerExecResize changes the size of the tty for an exec process running inside a container.
|
// ContainerExecResize changes the size of the tty for an exec process running inside a container.
|
||||||
func (cli *Client) ContainerExecResize(ctx context.Context, options types.ResizeOptions) error {
|
func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error {
|
||||||
return cli.resize(ctx, "/exec/"+options.ID, options.Height, options.Width)
|
return cli.resize(ctx, "/exec/"+execID, options.Height, options.Width)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) resize(ctx context.Context, basePath string, height, width int) error {
|
func (cli *Client) resize(ctx context.Context, basePath string, height, width int) error {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package client
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -20,7 +21,7 @@ var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`)
|
||||||
// ImageBuild sends request to the daemon to build images.
|
// ImageBuild sends request to the daemon to build images.
|
||||||
// The Body in the response implement an io.ReadCloser and it's up to the caller to
|
// The Body in the response implement an io.ReadCloser and it's up to the caller to
|
||||||
// close it.
|
// close it.
|
||||||
func (cli *Client) ImageBuild(ctx context.Context, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
||||||
query, err := imageBuildOptionsToQuery(options)
|
query, err := imageBuildOptionsToQuery(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ImageBuildResponse{}, err
|
return types.ImageBuildResponse{}, err
|
||||||
|
@ -34,7 +35,7 @@ func (cli *Client) ImageBuild(ctx context.Context, options types.ImageBuildOptio
|
||||||
headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
|
headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
|
||||||
headers.Set("Content-Type", "application/tar")
|
headers.Set("Content-Type", "application/tar")
|
||||||
|
|
||||||
serverResp, err := cli.postRaw(ctx, "/build", query, options.Context, headers)
|
serverResp, err := cli.postRaw(ctx, "/build", query, buildContext, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ImageBuildResponse{}, err
|
return types.ImageBuildResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,20 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
|
"github.com/docker/engine-api/types/reference"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageCreate creates a new image based in the parent options.
|
// ImageCreate creates a new image based in the parent options.
|
||||||
// It returns the JSON content in the response body.
|
// It returns the JSON content in the response body.
|
||||||
func (cli *Client) ImageCreate(ctx context.Context, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
||||||
|
repository, tag, err := reference.Parse(parentReference)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("fromImage", options.Parent)
|
query.Set("fromImage", repository)
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", tag)
|
||||||
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -6,22 +6,30 @@ import (
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageImport creates a new image based in the source options.
|
// ImageImport creates a new image based in the source options.
|
||||||
// It returns the JSON content in the response body.
|
// It returns the JSON content in the response body.
|
||||||
func (cli *Client) ImageImport(ctx context.Context, options types.ImageImportOptions) (io.ReadCloser, error) {
|
func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
|
||||||
|
if ref != "" {
|
||||||
|
//Check if the given image name can be resolved
|
||||||
|
if _, err := reference.ParseNamed(ref); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("fromSrc", options.SourceName)
|
query.Set("fromSrc", source.SourceName)
|
||||||
query.Set("repo", options.RepositoryName)
|
query.Set("repo", ref)
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", options.Tag)
|
||||||
query.Set("message", options.Message)
|
query.Set("message", options.Message)
|
||||||
for _, change := range options.Changes {
|
for _, change := range options.Changes {
|
||||||
query.Add("changes", change)
|
query.Add("changes", change)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.postRaw(ctx, "/images/create", query, options.Source, nil)
|
resp, err := cli.postRaw(ctx, "/images/create", query, source.Source, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,22 +8,32 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
|
"github.com/docker/engine-api/types/reference"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImagePull requests the docker host to pull an image from a remote registry.
|
// ImagePull requests the docker host to pull an image from a remote registry.
|
||||||
// It executes the privileged function if the operation is unauthorized
|
// It executes the privileged function if the operation is unauthorized
|
||||||
// and it tries one more time.
|
// and it tries one more time.
|
||||||
// It's up to the caller to handle the io.ReadCloser and close it properly.
|
// It's up to the caller to handle the io.ReadCloser and close it properly.
|
||||||
func (cli *Client) ImagePull(ctx context.Context, options types.ImagePullOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error) {
|
//
|
||||||
|
// FIXME(vdemeester): there is currently used in a few way in docker/docker
|
||||||
|
// - if not in trusted content, ref is used to pass the whole reference, and tag is empty
|
||||||
|
// - if in trusted content, ref is used to pass the reference name, and tag for the digest
|
||||||
|
func (cli *Client) ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
|
||||||
|
repository, tag, err := reference.Parse(ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("fromImage", options.ImageID)
|
query.Set("fromImage", repository)
|
||||||
if options.Tag != "" {
|
if tag != "" {
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
||||||
if resp.statusCode == http.StatusUnauthorized {
|
if resp.statusCode == http.StatusUnauthorized {
|
||||||
newAuthHeader, privilegeErr := privilegeFunc()
|
newAuthHeader, privilegeErr := options.PrivilegeFunc()
|
||||||
if privilegeErr != nil {
|
if privilegeErr != nil {
|
||||||
return nil, privilegeErr
|
return nil, privilegeErr
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,44 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
distreference "github.com/docker/distribution/reference"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
|
"github.com/docker/engine-api/types/reference"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImagePush requests the docker host to push an image to a remote registry.
|
// ImagePush requests the docker host to push an image to a remote registry.
|
||||||
// It executes the privileged function if the operation is unauthorized
|
// It executes the privileged function if the operation is unauthorized
|
||||||
// and it tries one more time.
|
// and it tries one more time.
|
||||||
// It's up to the caller to handle the io.ReadCloser and close it properly.
|
// It's up to the caller to handle the io.ReadCloser and close it properly.
|
||||||
func (cli *Client) ImagePush(ctx context.Context, options types.ImagePushOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error) {
|
func (cli *Client) ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
|
||||||
query := url.Values{}
|
distributionRef, err := distreference.ParseNamed(ref)
|
||||||
query.Set("tag", options.Tag)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := cli.tryImagePush(ctx, options.ImageID, query, options.RegistryAuth)
|
if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical {
|
||||||
|
return nil, errors.New("cannot push a digest reference")
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := reference.GetTagFromNamedRef(distributionRef)
|
||||||
|
|
||||||
|
query := url.Values{}
|
||||||
|
query.Set("tag", tag)
|
||||||
|
|
||||||
|
resp, err := cli.tryImagePush(ctx, distributionRef.Name(), query, options.RegistryAuth)
|
||||||
if resp.statusCode == http.StatusUnauthorized {
|
if resp.statusCode == http.StatusUnauthorized {
|
||||||
newAuthHeader, privilegeErr := privilegeFunc()
|
newAuthHeader, privilegeErr := options.PrivilegeFunc()
|
||||||
if privilegeErr != nil {
|
if privilegeErr != nil {
|
||||||
return nil, privilegeErr
|
return nil, privilegeErr
|
||||||
}
|
}
|
||||||
resp, err = cli.tryImagePush(ctx, options.ImageID, query, newAuthHeader)
|
resp, err = cli.tryImagePush(ctx, distributionRef.Name(), query, newAuthHeader)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageRemove removes an image from the docker host.
|
// ImageRemove removes an image from the docker host.
|
||||||
func (cli *Client) ImageRemove(ctx context.Context, options types.ImageRemoveOptions) ([]types.ImageDelete, error) {
|
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|
||||||
if options.Force {
|
if options.Force {
|
||||||
|
@ -19,7 +19,7 @@ func (cli *Client) ImageRemove(ctx context.Context, options types.ImageRemoveOpt
|
||||||
query.Set("noprune", "1")
|
query.Set("noprune", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.delete(ctx, "/images/"+options.ImageID, query, nil)
|
resp, err := cli.delete(ctx, "/images/"+imageID, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,14 @@ import (
|
||||||
|
|
||||||
// ImageSearch makes the docker host to search by a term in a remote registry.
|
// ImageSearch makes the docker host to search by a term in a remote registry.
|
||||||
// The list of results is not sorted in any fashion.
|
// The list of results is not sorted in any fashion.
|
||||||
func (cli *Client) ImageSearch(ctx context.Context, options types.ImageSearchOptions, privilegeFunc RequestPrivilegeFunc) ([]registry.SearchResult, error) {
|
func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) {
|
||||||
var results []registry.SearchResult
|
var results []registry.SearchResult
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("term", options.Term)
|
query.Set("term", term)
|
||||||
|
|
||||||
resp, err := cli.tryImageSearch(ctx, query, options.RegistryAuth)
|
resp, err := cli.tryImageSearch(ctx, query, options.RegistryAuth)
|
||||||
if resp.statusCode == http.StatusUnauthorized {
|
if resp.statusCode == http.StatusUnauthorized {
|
||||||
newAuthHeader, privilegeErr := privilegeFunc()
|
newAuthHeader, privilegeErr := options.PrivilegeFunc()
|
||||||
if privilegeErr != nil {
|
if privilegeErr != nil {
|
||||||
return results, privilegeErr
|
return results, privilegeErr
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,38 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/docker/engine-api/types"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
distreference "github.com/docker/distribution/reference"
|
||||||
|
"github.com/docker/engine-api/types"
|
||||||
|
"github.com/docker/engine-api/types/reference"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageTag tags an image in the docker host
|
// ImageTag tags an image in the docker host
|
||||||
func (cli *Client) ImageTag(ctx context.Context, options types.ImageTagOptions) error {
|
func (cli *Client) ImageTag(ctx context.Context, imageID, ref string, options types.ImageTagOptions) error {
|
||||||
|
distributionRef, err := distreference.ParseNamed(ref)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error parsing reference: %q is not a valid repository/tag", ref)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical {
|
||||||
|
return errors.New("refusing to create a tag with a digest reference")
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := reference.GetTagFromNamedRef(distributionRef)
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
query.Set("repo", options.RepositoryName)
|
query.Set("repo", distributionRef.Name())
|
||||||
query.Set("tag", options.Tag)
|
query.Set("tag", tag)
|
||||||
if options.Force {
|
if options.Force {
|
||||||
query.Set("force", "1")
|
query.Set("force", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.post(ctx, "/images/"+options.ImageID+"/tag", query, nil, nil)
|
resp, err := cli.post(ctx, "/images/"+imageID+"/tag", query, nil, nil)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,59 +15,60 @@ import (
|
||||||
// APIClient is an interface that clients that talk with a docker server must implement.
|
// APIClient is an interface that clients that talk with a docker server must implement.
|
||||||
type APIClient interface {
|
type APIClient interface {
|
||||||
ClientVersion() string
|
ClientVersion() string
|
||||||
ContainerAttach(ctx context.Context, options types.ContainerAttachOptions) (types.HijackedResponse, error)
|
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
|
||||||
ContainerCommit(ctx context.Context, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
|
ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
|
||||||
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error)
|
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (types.ContainerCreateResponse, error)
|
||||||
ContainerDiff(ctx context.Context, ontainerID string) ([]types.ContainerChange, error)
|
ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error)
|
||||||
ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
|
ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error)
|
||||||
ContainerExecCreate(ctx context.Context, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
|
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.ContainerExecCreateResponse, error)
|
||||||
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
|
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
|
||||||
ContainerExecResize(ctx context.Context, options types.ResizeOptions) error
|
ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error
|
||||||
ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
|
ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
|
||||||
ContainerExport(ctx context.Context, containerID string) (io.ReadCloser, error)
|
ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)
|
||||||
ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
|
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
|
||||||
ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (types.ContainerJSON, []byte, error)
|
ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
|
||||||
ContainerKill(ctx context.Context, containerID, signal string) error
|
ContainerKill(ctx context.Context, container, signal string) error
|
||||||
ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
|
ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
|
||||||
ContainerLogs(ctx context.Context, options types.ContainerLogsOptions) (io.ReadCloser, error)
|
ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||||
ContainerPause(ctx context.Context, containerID string) error
|
ContainerPause(ctx context.Context, container string) error
|
||||||
ContainerRemove(ctx context.Context, options types.ContainerRemoveOptions) error
|
ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error
|
||||||
ContainerRename(ctx context.Context, containerID, newContainerName string) error
|
ContainerRename(ctx context.Context, container, newContainerName string) error
|
||||||
ContainerResize(ctx context.Context, options types.ResizeOptions) error
|
ContainerResize(ctx context.Context, container string, options types.ResizeOptions) error
|
||||||
ContainerRestart(ctx context.Context, containerID string, timeout int) error
|
ContainerRestart(ctx context.Context, container string, timeout int) error
|
||||||
ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error)
|
ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
|
||||||
ContainerStats(ctx context.Context, containerID string, stream bool) (io.ReadCloser, error)
|
ContainerStats(ctx context.Context, container string, stream bool) (io.ReadCloser, error)
|
||||||
ContainerStart(ctx context.Context, containerID string) error
|
ContainerStart(ctx context.Context, container string) error
|
||||||
ContainerStop(ctx context.Context, containerID string, timeout int) error
|
ContainerStop(ctx context.Context, container string, timeout int) error
|
||||||
ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error)
|
ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error)
|
||||||
ContainerUnpause(ctx context.Context, containerID string) error
|
ContainerUnpause(ctx context.Context, container string) error
|
||||||
ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) error
|
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) error
|
||||||
ContainerWait(ctx context.Context, containerID string) (int, error)
|
ContainerWait(ctx context.Context, container string) (int, error)
|
||||||
CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
|
||||||
CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error
|
CopyToContainer(ctx context.Context, options types.CopyToContainerOptions) error
|
||||||
Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error)
|
Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error)
|
||||||
ImageBuild(ctx context.Context, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
||||||
ImageCreate(ctx context.Context, options types.ImageCreateOptions) (io.ReadCloser, error)
|
ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
|
||||||
ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error)
|
ImageHistory(ctx context.Context, image string) ([]types.ImageHistory, error)
|
||||||
ImageImport(ctx context.Context, options types.ImageImportOptions) (io.ReadCloser, error)
|
ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error)
|
||||||
ImageInspectWithRaw(ctx context.Context, imageID string, getSize bool) (types.ImageInspect, []byte, error)
|
ImageInspectWithRaw(ctx context.Context, image string, getSize bool) (types.ImageInspect, []byte, error)
|
||||||
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.Image, error)
|
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.Image, error)
|
||||||
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
|
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
|
||||||
ImagePull(ctx context.Context, options types.ImagePullOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error)
|
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
|
||||||
ImagePush(ctx context.Context, options types.ImagePushOptions, privilegeFunc RequestPrivilegeFunc) (io.ReadCloser, error)
|
ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error)
|
||||||
ImageRemove(ctx context.Context, options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
||||||
ImageSearch(ctx context.Context, options types.ImageSearchOptions, privilegeFunc RequestPrivilegeFunc) ([]registry.SearchResult, error)
|
ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
|
||||||
ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error)
|
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
|
||||||
ImageTag(ctx context.Context, options types.ImageTagOptions) error
|
ImageTag(ctx context.Context, image, ref string, options types.ImageTagOptions) error
|
||||||
Info(ctx context.Context) (types.Info, error)
|
Info(ctx context.Context) (types.Info, error)
|
||||||
NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error
|
NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
|
||||||
NetworkCreate(ctx context.Context, options types.NetworkCreate) (types.NetworkCreateResponse, error)
|
NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
|
||||||
NetworkDisconnect(ctx context.Context, networkID, containerID string, force bool) error
|
NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error
|
||||||
NetworkInspect(ctx context.Context, networkID string) (types.NetworkResource, error)
|
NetworkInspect(ctx context.Context, networkID string) (types.NetworkResource, error)
|
||||||
NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
|
NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
|
||||||
NetworkRemove(ctx context.Context, networkID string) error
|
NetworkRemove(ctx context.Context, networkID string) error
|
||||||
RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error)
|
RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error)
|
||||||
ServerVersion(ctx context.Context) (types.Version, error)
|
ServerVersion(ctx context.Context) (types.Version, error)
|
||||||
|
UpdateClientVersion(v string)
|
||||||
VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error)
|
VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error)
|
||||||
VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error)
|
VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error)
|
||||||
VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error)
|
VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error)
|
||||||
|
|
|
@ -8,9 +8,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkCreate creates a new network in the docker host.
|
// NetworkCreate creates a new network in the docker host.
|
||||||
func (cli *Client) NetworkCreate(ctx context.Context, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
func (cli *Client) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
||||||
|
networkCreateRequest := types.NetworkCreateRequest{
|
||||||
|
NetworkCreate: options,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
var response types.NetworkCreateResponse
|
var response types.NetworkCreateResponse
|
||||||
serverResp, err := cli.post(ctx, "/networks/create", nil, options, nil)
|
serverResp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// RequestPrivilegeFunc is a function interface that
|
|
||||||
// clients can supply to retry operations after
|
|
||||||
// getting an authorization error.
|
|
||||||
// This function returns the registry authentication
|
|
||||||
// header value in base 64 format, or an error
|
|
||||||
// if the privilege request fails.
|
|
||||||
type RequestPrivilegeFunc func() (string, error)
|
|
||||||
|
|
|
@ -56,12 +56,14 @@ func (cli *Client) delete(ctx context.Context, path string, query url.Values, he
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, obj interface{}, headers map[string][]string) (*serverResponse, error) {
|
func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, obj interface{}, headers map[string][]string) (*serverResponse, error) {
|
||||||
body, err := encodeData(obj)
|
var body io.Reader
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if body != nil {
|
if obj != nil {
|
||||||
|
var err error
|
||||||
|
body, err = encodeData(obj)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if headers == nil {
|
if headers == nil {
|
||||||
headers = make(map[string][]string)
|
headers = make(map[string][]string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,24 +12,21 @@ import (
|
||||||
|
|
||||||
// ContainerAttachOptions holds parameters to attach to a container.
|
// ContainerAttachOptions holds parameters to attach to a container.
|
||||||
type ContainerAttachOptions struct {
|
type ContainerAttachOptions struct {
|
||||||
ContainerID string
|
Stream bool
|
||||||
Stream bool
|
Stdin bool
|
||||||
Stdin bool
|
Stdout bool
|
||||||
Stdout bool
|
Stderr bool
|
||||||
Stderr bool
|
DetachKeys string
|
||||||
DetachKeys string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerCommitOptions holds parameters to commit changes into a container.
|
// ContainerCommitOptions holds parameters to commit changes into a container.
|
||||||
type ContainerCommitOptions struct {
|
type ContainerCommitOptions struct {
|
||||||
ContainerID string
|
Reference string
|
||||||
RepositoryName string
|
Comment string
|
||||||
Tag string
|
Author string
|
||||||
Comment string
|
Changes []string
|
||||||
Author string
|
Pause bool
|
||||||
Changes []string
|
Config *container.Config
|
||||||
Pause bool
|
|
||||||
Config *container.Config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerExecInspect holds information returned by exec inspect.
|
// ContainerExecInspect holds information returned by exec inspect.
|
||||||
|
@ -54,18 +51,16 @@ type ContainerListOptions struct {
|
||||||
|
|
||||||
// ContainerLogsOptions holds parameters to filter logs with.
|
// ContainerLogsOptions holds parameters to filter logs with.
|
||||||
type ContainerLogsOptions struct {
|
type ContainerLogsOptions struct {
|
||||||
ContainerID string
|
ShowStdout bool
|
||||||
ShowStdout bool
|
ShowStderr bool
|
||||||
ShowStderr bool
|
Since string
|
||||||
Since string
|
Timestamps bool
|
||||||
Timestamps bool
|
Follow bool
|
||||||
Follow bool
|
Tail string
|
||||||
Tail string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerRemoveOptions holds parameters to remove containers.
|
// ContainerRemoveOptions holds parameters to remove containers.
|
||||||
type ContainerRemoveOptions struct {
|
type ContainerRemoveOptions struct {
|
||||||
ContainerID string
|
|
||||||
RemoveVolumes bool
|
RemoveVolumes bool
|
||||||
RemoveLinks bool
|
RemoveLinks bool
|
||||||
Force bool
|
Force bool
|
||||||
|
@ -155,19 +150,20 @@ type ImageBuildResponse struct {
|
||||||
|
|
||||||
// ImageCreateOptions holds information to create images.
|
// ImageCreateOptions holds information to create images.
|
||||||
type ImageCreateOptions struct {
|
type ImageCreateOptions struct {
|
||||||
Parent string // Parent is the name of the image to pull
|
|
||||||
Tag string // Tag is the name to tag this image with
|
|
||||||
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImageImportSource holds source information for ImageImport
|
||||||
|
type ImageImportSource struct {
|
||||||
|
Source io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName)
|
||||||
|
SourceName string // SourceName is the name of the image to pull (mutually exclusive with Source)
|
||||||
|
}
|
||||||
|
|
||||||
// ImageImportOptions holds information to import images from the client host.
|
// ImageImportOptions holds information to import images from the client host.
|
||||||
type ImageImportOptions struct {
|
type ImageImportOptions struct {
|
||||||
Source io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName)
|
Tag string // Tag is the name to tag this image with. This attribute is deprecated.
|
||||||
SourceName string // SourceName is the name of the image to pull (mutually exclusive with Source)
|
Message string // Message is the message to tag the image with
|
||||||
RepositoryName string // RepositoryName is the name of the repository to import this image into
|
Changes []string // Changes are the raw changes to apply to this image
|
||||||
Message string // Message is the message to tag the image with
|
|
||||||
Tag string // Tag is the name to tag this image with
|
|
||||||
Changes []string // Changes are the raw changes to apply to this image
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageListOptions holds parameters to filter the list of images with.
|
// ImageListOptions holds parameters to filter the list of images with.
|
||||||
|
@ -185,40 +181,42 @@ type ImageLoadResponse struct {
|
||||||
|
|
||||||
// ImagePullOptions holds information to pull images.
|
// ImagePullOptions holds information to pull images.
|
||||||
type ImagePullOptions struct {
|
type ImagePullOptions struct {
|
||||||
ImageID string // ImageID is the name of the image to pull
|
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
||||||
Tag string // Tag is the name of the tag to be pulled
|
PrivilegeFunc RequestPrivilegeFunc
|
||||||
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestPrivilegeFunc is a function interface that
|
||||||
|
// clients can supply to retry operations after
|
||||||
|
// getting an authorization error.
|
||||||
|
// This function returns the registry authentication
|
||||||
|
// header value in base 64 format, or an error
|
||||||
|
// if the privilege request fails.
|
||||||
|
type RequestPrivilegeFunc func() (string, error)
|
||||||
|
|
||||||
//ImagePushOptions holds information to push images.
|
//ImagePushOptions holds information to push images.
|
||||||
type ImagePushOptions ImagePullOptions
|
type ImagePushOptions ImagePullOptions
|
||||||
|
|
||||||
// ImageRemoveOptions holds parameters to remove images.
|
// ImageRemoveOptions holds parameters to remove images.
|
||||||
type ImageRemoveOptions struct {
|
type ImageRemoveOptions struct {
|
||||||
ImageID string
|
|
||||||
Force bool
|
Force bool
|
||||||
PruneChildren bool
|
PruneChildren bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageSearchOptions holds parameters to search images with.
|
// ImageSearchOptions holds parameters to search images with.
|
||||||
type ImageSearchOptions struct {
|
type ImageSearchOptions struct {
|
||||||
Term string
|
RegistryAuth string
|
||||||
RegistryAuth string
|
PrivilegeFunc RequestPrivilegeFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageTagOptions holds parameters to tag an image
|
// ImageTagOptions holds parameters to tag an image
|
||||||
type ImageTagOptions struct {
|
type ImageTagOptions struct {
|
||||||
ImageID string
|
Force bool
|
||||||
RepositoryName string
|
|
||||||
Tag string
|
|
||||||
Force bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResizeOptions holds parameters to resize a tty.
|
// ResizeOptions holds parameters to resize a tty.
|
||||||
// It can be used to resize container ttys and
|
// It can be used to resize container ttys and
|
||||||
// exec process ttys too.
|
// exec process ttys too.
|
||||||
type ResizeOptions struct {
|
type ResizeOptions struct {
|
||||||
ID string
|
|
||||||
Height int
|
Height int
|
||||||
Width int
|
Width int
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ type ExecConfig struct {
|
||||||
User string // User that will run the command
|
User string // User that will run the command
|
||||||
Privileged bool // Is the container in privileged mode
|
Privileged bool // Is the container in privileged mode
|
||||||
Tty bool // Attach standard streams to a tty.
|
Tty bool // Attach standard streams to a tty.
|
||||||
Container string // Name of the container (to execute in)
|
|
||||||
AttachStdin bool // Attach the standard input, makes possible user interaction
|
AttachStdin bool // Attach the standard input, makes possible user interaction
|
||||||
AttachStderr bool // Attach the standard output
|
AttachStderr bool // Attach the standard output
|
||||||
AttachStdout bool // Attach the standard error
|
AttachStdout bool // Attach the standard error
|
||||||
|
|
|
@ -19,7 +19,6 @@ type Config struct {
|
||||||
AttachStdout bool // Attach the standard output
|
AttachStdout bool // Attach the standard output
|
||||||
AttachStderr bool // Attach the standard error
|
AttachStderr bool // Attach the standard error
|
||||||
ExposedPorts map[nat.Port]struct{} `json:",omitempty"` // List of exposed ports
|
ExposedPorts map[nat.Port]struct{} `json:",omitempty"` // List of exposed ports
|
||||||
PublishService string `json:",omitempty"` // Name of the network service exposed by the container
|
|
||||||
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
||||||
OpenStdin bool // Open stdin
|
OpenStdin bool // Open stdin
|
||||||
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
||||||
|
|
|
@ -92,11 +92,13 @@ func (n UsernsMode) Valid() bool {
|
||||||
// CgroupSpec represents the cgroup to use for the container.
|
// CgroupSpec represents the cgroup to use for the container.
|
||||||
type CgroupSpec string
|
type CgroupSpec string
|
||||||
|
|
||||||
|
// IsContainer indicates whether the container is using another container cgroup
|
||||||
func (c CgroupSpec) IsContainer() bool {
|
func (c CgroupSpec) IsContainer() bool {
|
||||||
parts := strings.SplitN(string(c), ":", 2)
|
parts := strings.SplitN(string(c), ":", 2)
|
||||||
return len(parts) > 1 && parts[0] == "container"
|
return len(parts) > 1 && parts[0] == "container"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Valid indicates whether the cgroup spec is valid.
|
||||||
func (c CgroupSpec) Valid() bool {
|
func (c CgroupSpec) Valid() bool {
|
||||||
return c.IsContainer() || c == ""
|
return c.IsContainer() || c == ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,6 +69,28 @@ func ToParam(a Args) (string, error) {
|
||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToParamWithVersion packs the Args into a string for easy transport from client to server.
|
||||||
|
// The generated string will depend on the specified version (corresponding to the API version).
|
||||||
|
func ToParamWithVersion(version string, a Args) (string, error) {
|
||||||
|
// this way we don't URL encode {}, just empty space
|
||||||
|
if a.Len() == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// for daemons older than v1.10, filter must be of the form map[string][]string
|
||||||
|
buf := []byte{}
|
||||||
|
err := errors.New("")
|
||||||
|
if version != "" && compareTo(version, "1.22") == -1 {
|
||||||
|
buf, err = json.Marshal(convertArgsToSlice(a.fields))
|
||||||
|
} else {
|
||||||
|
buf, err = json.Marshal(a.fields)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
// FromParam unpacks the filter Args.
|
// FromParam unpacks the filter Args.
|
||||||
func FromParam(p string) (Args, error) {
|
func FromParam(p string) (Args, error) {
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
|
@ -255,3 +278,48 @@ func deprecatedArgs(d map[string][]string) map[string]map[string]bool {
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertArgsToSlice(f map[string]map[string]bool) map[string][]string {
|
||||||
|
m := map[string][]string{}
|
||||||
|
for k, v := range f {
|
||||||
|
values := []string{}
|
||||||
|
for kk := range v {
|
||||||
|
if v[kk] {
|
||||||
|
values = append(values, kk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m[k] = values
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// compareTo compares two version strings
|
||||||
|
// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise
|
||||||
|
func compareTo(v1, v2 string) int {
|
||||||
|
var (
|
||||||
|
currTab = strings.Split(v1, ".")
|
||||||
|
otherTab = strings.Split(v2, ".")
|
||||||
|
)
|
||||||
|
|
||||||
|
max := len(currTab)
|
||||||
|
if len(otherTab) > max {
|
||||||
|
max = len(otherTab)
|
||||||
|
}
|
||||||
|
for i := 0; i < max; i++ {
|
||||||
|
var currInt, otherInt int
|
||||||
|
|
||||||
|
if len(currTab) > i {
|
||||||
|
currInt, _ = strconv.Atoi(currTab[i])
|
||||||
|
}
|
||||||
|
if len(otherTab) > i {
|
||||||
|
otherInt, _ = strconv.Atoi(otherTab[i])
|
||||||
|
}
|
||||||
|
if currInt > otherInt {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if otherInt > currInt {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package reference
|
||||||
|
|
||||||
|
import (
|
||||||
|
distreference "github.com/docker/distribution/reference"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parse parses the given references and return the repository and
|
||||||
|
// tag (if present) from it. If there is an error during parsing, it will
|
||||||
|
// return an error.
|
||||||
|
func Parse(ref string) (string, string, error) {
|
||||||
|
distributionRef, err := distreference.ParseNamed(ref)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
tag := GetTagFromNamedRef(distributionRef)
|
||||||
|
return distributionRef.Name(), tag, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTagFromNamedRef returns a tag from the specified reference.
|
||||||
|
// This function is necessary as long as the docker "server" api make the distinction between repository
|
||||||
|
// and tags.
|
||||||
|
func GetTagFromNamedRef(ref distreference.Named) string {
|
||||||
|
var tag string
|
||||||
|
switch x := ref.(type) {
|
||||||
|
case distreference.Digested:
|
||||||
|
tag = x.Digest().String()
|
||||||
|
case distreference.NamedTagged:
|
||||||
|
tag = x.Tag()
|
||||||
|
}
|
||||||
|
return tag
|
||||||
|
}
|
|
@ -91,6 +91,9 @@ type NetworkStats struct {
|
||||||
type PidsStats struct {
|
type PidsStats struct {
|
||||||
// Current is the number of pids in the cgroup
|
// Current is the number of pids in the cgroup
|
||||||
Current uint64 `json:"current,omitempty"`
|
Current uint64 `json:"current,omitempty"`
|
||||||
|
// Limit is the hard limit on the number of pids in the cgroup.
|
||||||
|
// A "Limit" of 0 means that there is no limit.
|
||||||
|
Limit uint64 `json:"limit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats is Ultimate struct aggregating all types of stats of one container
|
// Stats is Ultimate struct aggregating all types of stats of one container
|
||||||
|
|
|
@ -290,7 +290,7 @@ type ContainerState struct {
|
||||||
FinishedAt string
|
FinishedAt string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeData stores information about the node that a container
|
// ContainerNode stores information about the node that a container
|
||||||
// is running on. It's only available in Docker Swarm
|
// is running on. It's only available in Docker Swarm
|
||||||
type ContainerNode struct {
|
type ContainerNode struct {
|
||||||
ID string
|
ID string
|
||||||
|
@ -438,7 +438,6 @@ type EndpointResource struct {
|
||||||
|
|
||||||
// NetworkCreate is the expected body of the "create network" http request message
|
// NetworkCreate is the expected body of the "create network" http request message
|
||||||
type NetworkCreate struct {
|
type NetworkCreate struct {
|
||||||
Name string
|
|
||||||
CheckDuplicate bool
|
CheckDuplicate bool
|
||||||
Driver string
|
Driver string
|
||||||
EnableIPv6 bool
|
EnableIPv6 bool
|
||||||
|
@ -448,6 +447,12 @@ type NetworkCreate struct {
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetworkCreateRequest is the request message sent to the server for network create call.
|
||||||
|
type NetworkCreateRequest struct {
|
||||||
|
NetworkCreate
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
// NetworkCreateResponse is the response message sent by the server for network create call
|
// NetworkCreateResponse is the response message sent by the server for network create call
|
||||||
type NetworkCreateResponse struct {
|
type NetworkCreateResponse struct {
|
||||||
ID string `json:"Id"`
|
ID string `json:"Id"`
|
||||||
|
|
Loading…
Reference in New Issue