mirror of https://github.com/docker/docs.git
godeps update
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
parent
c82a953422
commit
acdb67bd63
|
@ -105,7 +105,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samalba/dockerclient",
|
"ImportPath": "github.com/samalba/dockerclient",
|
||||||
"Rev": "15ebe064ca62ad0d64834e7ef0d4ed8ce9d02cde"
|
"Rev": "2bd0abc1edafed71d634778312f534b7798d3a94"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
||||||
|
|
|
@ -14,8 +14,25 @@ type AuthConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// encode the auth configuration struct into base64 for the X-Registry-Auth header
|
// encode the auth configuration struct into base64 for the X-Registry-Auth header
|
||||||
func (c *AuthConfig) encode() string {
|
func (c *AuthConfig) encode() (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
json.NewEncoder(&buf).Encode(c)
|
if err := json.NewEncoder(&buf).Encode(c); err != nil {
|
||||||
return base64.URLEncoding.EncodeToString(buf.Bytes())
|
return "", err
|
||||||
|
}
|
||||||
|
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigFile holds parameters for authenticating during a BuildImage request
|
||||||
|
type ConfigFile struct {
|
||||||
|
Configs map[string]AuthConfig `json:"configs,omitempty"`
|
||||||
|
rootPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
// encode the configuration struct into base64 for the X-Registry-Config header
|
||||||
|
func (c *ConfigFile) encode() (string, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := json.NewEncoder(&buf).Encode(c); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
func TestAuthEncode(t *testing.T) {
|
func TestAuthEncode(t *testing.T) {
|
||||||
a := AuthConfig{Username: "foo", Password: "password", Email: "bar@baz.com"}
|
a := AuthConfig{Username: "foo", Password: "password", Email: "bar@baz.com"}
|
||||||
expected := "eyJ1c2VybmFtZSI6ImZvbyIsInBhc3N3b3JkIjoicGFzc3dvcmQiLCJlbWFpbCI6ImJhckBiYXouY29tIn0K"
|
expected := "eyJ1c2VybmFtZSI6ImZvbyIsInBhc3N3b3JkIjoicGFzc3dvcmQiLCJlbWFpbCI6ImJhckBiYXouY29tIn0K"
|
||||||
got := a.encode()
|
got, _ := a.encode()
|
||||||
|
|
||||||
if expected != got {
|
if expected != got {
|
||||||
t.Errorf("testAuthEncode failed. Expected [%s] got [%s]", expected, got)
|
t.Errorf("testAuthEncode failed. Expected [%s] got [%s]", expected, got)
|
||||||
|
|
|
@ -235,21 +235,30 @@ func (client *DockerClient) readJSONStream(stream io.ReadCloser, decode func(*js
|
||||||
resultChan := make(chan decodingResult)
|
resultChan := make(chan decodingResult)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
decoder := json.NewDecoder(stream)
|
decodeChan := make(chan decodingResult)
|
||||||
stopped := make(chan struct{})
|
|
||||||
go func() {
|
go func() {
|
||||||
<-stopChan
|
decoder := json.NewDecoder(stream)
|
||||||
stream.Close()
|
for {
|
||||||
stopped <- struct{}{}
|
decodeResult := decode(decoder)
|
||||||
|
decodeChan <- decodeResult
|
||||||
|
if decodeResult.err != nil {
|
||||||
|
close(decodeChan)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
defer close(resultChan)
|
defer close(resultChan)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
decodeResult := decode(decoder)
|
|
||||||
select {
|
select {
|
||||||
case <-stopped:
|
case <-stopChan:
|
||||||
|
stream.Close()
|
||||||
|
for range decodeChan {
|
||||||
|
}
|
||||||
return
|
return
|
||||||
default:
|
case decodeResult := <-decodeChan:
|
||||||
resultChan <- decodeResult
|
resultChan <- decodeResult
|
||||||
if decodeResult.err != nil {
|
if decodeResult.err != nil {
|
||||||
stream.Close()
|
stream.Close()
|
||||||
|
@ -257,6 +266,7 @@ func (client *DockerClient) readJSONStream(stream io.ReadCloser, decode func(*js
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return resultChan
|
return resultChan
|
||||||
|
@ -366,13 +376,17 @@ func (client *DockerClient) StartMonitorEvents(cb Callback, ec chan error, args
|
||||||
go func() {
|
go func() {
|
||||||
eventErrChan, err := client.MonitorEvents(nil, client.eventStopChan)
|
eventErrChan, err := client.MonitorEvents(nil, client.eventStopChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec <- err
|
if ec != nil {
|
||||||
|
ec <- err
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for e := range eventErrChan {
|
for e := range eventErrChan {
|
||||||
if e.Error != nil {
|
if e.Error != nil {
|
||||||
ec <- err
|
if ec != nil {
|
||||||
|
ec <- err
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cb(&e.Event, ec, args...)
|
cb(&e.Event, ec, args...)
|
||||||
|
@ -447,7 +461,11 @@ func (client *DockerClient) PullImage(name string, auth *AuthConfig) error {
|
||||||
uri := fmt.Sprintf("/%s/images/create?%s", APIVersion, v.Encode())
|
uri := fmt.Sprintf("/%s/images/create?%s", APIVersion, v.Encode())
|
||||||
req, err := http.NewRequest("POST", client.URL.String()+uri, nil)
|
req, err := http.NewRequest("POST", client.URL.String()+uri, nil)
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
req.Header.Add("X-Registry-Auth", auth.encode())
|
encoded_auth, err := auth.encode()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Add("X-Registry-Auth", encoded_auth)
|
||||||
}
|
}
|
||||||
resp, err := client.HTTPClient.Do(req)
|
resp, err := client.HTTPClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -521,8 +539,12 @@ func (client *DockerClient) RemoveContainer(id string, force, volumes bool) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *DockerClient) ListImages() ([]*Image, error) {
|
func (client *DockerClient) ListImages(all bool) ([]*Image, error) {
|
||||||
uri := fmt.Sprintf("/%s/images/json", APIVersion)
|
argAll := 0
|
||||||
|
if all {
|
||||||
|
argAll = 1
|
||||||
|
}
|
||||||
|
uri := fmt.Sprintf("/%s/images/json?all=%d", APIVersion, argAll)
|
||||||
data, err := client.doRequest("GET", uri, nil, nil)
|
data, err := client.doRequest("GET", uri, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -615,3 +637,58 @@ func (client *DockerClient) ImportImage(source string, repository string, tag st
|
||||||
}
|
}
|
||||||
return client.doStreamRequest("POST", "/images/create?"+v.Encode(), in, nil)
|
return client.doStreamRequest("POST", "/images/create?"+v.Encode(), in, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *DockerClient) BuildImage(image *BuildImage) (io.ReadCloser, error) {
|
||||||
|
v := url.Values{}
|
||||||
|
|
||||||
|
if image.DockerfileName != "" {
|
||||||
|
v.Set("dockerfile", image.DockerfileName)
|
||||||
|
}
|
||||||
|
if image.RepoName != "" {
|
||||||
|
v.Set("t", image.RepoName)
|
||||||
|
}
|
||||||
|
if image.RemoteURL != "" {
|
||||||
|
v.Set("remote", image.RemoteURL)
|
||||||
|
}
|
||||||
|
if image.NoCache {
|
||||||
|
v.Set("nocache", "1")
|
||||||
|
}
|
||||||
|
if image.Pull {
|
||||||
|
v.Set("pull", "1")
|
||||||
|
}
|
||||||
|
if image.Remove {
|
||||||
|
v.Set("rm", "1")
|
||||||
|
} else {
|
||||||
|
v.Set("rm", "0")
|
||||||
|
}
|
||||||
|
if image.ForceRemove {
|
||||||
|
v.Set("forcerm", "1")
|
||||||
|
}
|
||||||
|
if image.SuppressOutput {
|
||||||
|
v.Set("q", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Set("memory", strconv.FormatInt(image.Memory, 10))
|
||||||
|
v.Set("memswap", strconv.FormatInt(image.MemorySwap, 10))
|
||||||
|
v.Set("cpushares", strconv.FormatInt(image.CpuShares, 10))
|
||||||
|
v.Set("cpuperiod", strconv.FormatInt(image.CpuPeriod, 10))
|
||||||
|
v.Set("cpuquota", strconv.FormatInt(image.CpuQuota, 10))
|
||||||
|
v.Set("cpusetcpus", image.CpuSetCpus)
|
||||||
|
v.Set("cpusetmems", image.CpuSetMems)
|
||||||
|
v.Set("cgroupparent", image.CgroupParent)
|
||||||
|
|
||||||
|
headers := make(map[string]string)
|
||||||
|
if image.Config != nil {
|
||||||
|
encoded_config, err := image.Config.encode()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
headers["X-Registry-Config"] = encoded_config
|
||||||
|
}
|
||||||
|
if image.Context != nil {
|
||||||
|
headers["Content-Type"] = "application/tar"
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf("/%s/build?%s", APIVersion, v.Encode())
|
||||||
|
return client.doStreamRequest("POST", uri, image.Context, headers)
|
||||||
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func handleContainerLogs(w http.ResponseWriter, r *http.Request) {
|
||||||
for ; i < 50; i++ {
|
for ; i < 50; i++ {
|
||||||
line := fmt.Sprintf("line %d", i)
|
line := fmt.Sprintf("line %d", i)
|
||||||
if getBoolValue(r.Form.Get("timestamps")) {
|
if getBoolValue(r.Form.Get("timestamps")) {
|
||||||
l := &jsonlog.JSONLog{Log: line, Created: time.Now()}
|
l := &jsonlog.JSONLog{Log: line, Created: time.Now().UTC()}
|
||||||
line = fmt.Sprintf("%s %s", l.Created.Format(timeutils.RFC3339NanoFixed), line)
|
line = fmt.Sprintf("%s %s", l.Created.Format(timeutils.RFC3339NanoFixed), line)
|
||||||
}
|
}
|
||||||
if i%2 == 0 && stderr {
|
if i%2 == 0 && stderr {
|
||||||
|
|
|
@ -35,10 +35,11 @@ type Client interface {
|
||||||
PullImage(name string, auth *AuthConfig) error
|
PullImage(name string, auth *AuthConfig) error
|
||||||
LoadImage(reader io.Reader) error
|
LoadImage(reader io.Reader) error
|
||||||
RemoveContainer(id string, force, volumes bool) error
|
RemoveContainer(id string, force, volumes bool) error
|
||||||
ListImages() ([]*Image, error)
|
ListImages(all bool) ([]*Image, error)
|
||||||
RemoveImage(name string) ([]*ImageDelete, error)
|
RemoveImage(name string) ([]*ImageDelete, error)
|
||||||
PauseContainer(name string) error
|
PauseContainer(name string) error
|
||||||
UnpauseContainer(name string) error
|
UnpauseContainer(name string) error
|
||||||
RenameContainer(oldName string, newName string) error
|
RenameContainer(oldName string, newName string) error
|
||||||
ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error)
|
ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error)
|
||||||
|
BuildImage(image BuildImage) (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,8 +116,8 @@ func (client *MockClient) RemoveContainer(id string, force, volumes bool) error
|
||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *MockClient) ListImages() ([]*dockerclient.Image, error) {
|
func (client *MockClient) ListImages(all bool) ([]*dockerclient.Image, error) {
|
||||||
args := client.Mock.Called()
|
args := client.Mock.Called(all)
|
||||||
return args.Get(0).([]*dockerclient.Image), args.Error(1)
|
return args.Get(0).([]*dockerclient.Image), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,3 +150,8 @@ func (client *MockClient) ImportImage(source string, repository string, tag stri
|
||||||
args := client.Mock.Called(source, repository, tag, tar)
|
args := client.Mock.Called(source, repository, tag, tar)
|
||||||
return args.Get(0).(io.ReadCloser), args.Error(1)
|
return args.Get(0).(io.ReadCloser), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *MockClient) BuildImage(image *dockerclient.BuildImage) (io.ReadCloser, error) {
|
||||||
|
args := client.Mock.Called(image)
|
||||||
|
return args.Get(0).(io.ReadCloser), args.Error(1)
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dockerclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/units"
|
"github.com/docker/docker/pkg/units"
|
||||||
|
@ -415,3 +416,24 @@ type LogConfig struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Config map[string]string `json:"config"`
|
Config map[string]string `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BuildImage struct {
|
||||||
|
Config *ConfigFile
|
||||||
|
DockerfileName string
|
||||||
|
Context io.Reader
|
||||||
|
RemoteURL string
|
||||||
|
RepoName string
|
||||||
|
SuppressOutput bool
|
||||||
|
NoCache bool
|
||||||
|
Remove bool
|
||||||
|
ForceRemove bool
|
||||||
|
Pull bool
|
||||||
|
Memory int64
|
||||||
|
MemorySwap int64
|
||||||
|
CpuShares int64
|
||||||
|
CpuPeriod int64
|
||||||
|
CpuQuota int64
|
||||||
|
CpuSetCpus string
|
||||||
|
CpuSetMems string
|
||||||
|
CgroupParent string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue