Merge pull request #684 from vieux/private_pull

support pulling private images from docker pull
This commit is contained in:
Andrea Luzzardi 2015-04-28 15:48:20 -07:00
commit 246bee3b62
4 changed files with 15 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package api
import ( import (
"bytes" "bytes"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -251,6 +252,11 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
wf := NewWriteFlusher(w) wf := NewWriteFlusher(w)
if image := r.Form.Get("fromImage"); image != "" { //pull if image := r.Form.Get("fromImage"); image != "" { //pull
authConfig := dockerclient.AuthConfig{}
buf, err := base64.URLEncoding.DecodeString(r.Header.Get("X-Registry-Auth"))
if err == nil {
json.Unmarshal(buf, &authConfig)
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
@ -264,7 +270,7 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(wf, "{%q:%q,%q:\"Pulling %s... : %s\",%q:{}}", "id", what, "status", image, status, "progressDetail") fmt.Fprintf(wf, "{%q:%q,%q:\"Pulling %s... : %s\",%q:{}}", "id", what, "status", image, status, "progressDetail")
} }
} }
c.cluster.Pull(image, callback) c.cluster.Pull(image, &authConfig, callback)
} else { //import } else { //import
httpError(w, "Not supported in clustering mode.", http.StatusNotImplemented) httpError(w, "Not supported in clustering mode.", http.StatusNotImplemented)
} }

View File

@ -1,8 +1,9 @@
package cluster package cluster
import ( import (
"github.com/samalba/dockerclient"
"io" "io"
"github.com/samalba/dockerclient"
) )
// Cluster is exported // Cluster is exported
@ -32,7 +33,7 @@ type Cluster interface {
// `callback` can be called multiple time // `callback` can be called multiple time
// `what` is what is being pulled // `what` is what is being pulled
// `status` is the current status, like "", "in progress" or "downloaded // `status` is the current status, like "", "in progress" or "downloaded
Pull(name string, callback func(what, status string)) Pull(name string, authConfig *dockerclient.AuthConfig, callback func(what, status string))
// Load images // Load images
// `callback` can be called multiple time // `callback` can be called multiple time

View File

@ -367,7 +367,7 @@ func (e *Engine) Create(config *dockerclient.ContainerConfig, name string, pullI
return nil, err return nil, err
} }
// Otherwise, try to pull the image... // Otherwise, try to pull the image...
if err = e.Pull(config.Image); err != nil { if err = e.Pull(config.Image, nil); err != nil {
return nil, err return nil, err
} }
// ...And try agaie. // ...And try agaie.
@ -402,11 +402,11 @@ func (e *Engine) Destroy(container *Container, force bool) error {
} }
// Pull an image on the engine // Pull an image on the engine
func (e *Engine) Pull(image string) error { func (e *Engine) Pull(image string, authConfig *dockerclient.AuthConfig) error {
if !strings.Contains(image, ":") { if !strings.Contains(image, ":") {
image = image + ":latest" image = image + ":latest"
} }
if err := e.client.PullImage(image, nil); err != nil { if err := e.client.PullImage(image, authConfig); err != nil {
return err return err
} }

View File

@ -212,7 +212,7 @@ func (c *Cluster) RemoveImage(image *cluster.Image) ([]*dockerclient.ImageDelete
} }
// Pull is exported // Pull is exported
func (c *Cluster) Pull(name string, callback func(what, status string)) { func (c *Cluster) Pull(name string, authConfig *dockerclient.AuthConfig, callback func(what, status string)) {
var wg sync.WaitGroup var wg sync.WaitGroup
c.RLock() c.RLock()
@ -225,7 +225,7 @@ func (c *Cluster) Pull(name string, callback func(what, status string)) {
if callback != nil { if callback != nil {
callback(nn.Name, "") callback(nn.Name, "")
} }
err := nn.Pull(name) err := nn.Pull(name, authConfig)
if callback != nil { if callback != nil {
if err != nil { if err != nil {
callback(nn.Name, err.Error()) callback(nn.Name, err.Error())