|
@@ -14,8 +14,8 @@ import (
|
|
|
"github.com/docker/distribution/digest"
|
|
|
"github.com/docker/docker/engine"
|
|
|
"github.com/docker/docker/image"
|
|
|
- "github.com/docker/docker/pkg/common"
|
|
|
"github.com/docker/docker/pkg/progressreader"
|
|
|
+ "github.com/docker/docker/pkg/stringid"
|
|
|
"github.com/docker/docker/registry"
|
|
|
"github.com/docker/docker/utils"
|
|
|
)
|
|
@@ -172,9 +172,9 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
|
|
|
// ensure no two downloads of the same image happen at the same time
|
|
|
if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
|
|
|
if c != nil {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
|
|
|
<-c
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Download complete", nil))
|
|
|
} else {
|
|
|
log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
|
|
|
}
|
|
@@ -185,12 +185,12 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
|
|
|
}
|
|
|
defer s.poolRemove("pull", "img:"+img.ID)
|
|
|
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s", img.Tag, repoInfo.CanonicalName), nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s", img.Tag, repoInfo.CanonicalName), nil))
|
|
|
success := false
|
|
|
var lastErr, err error
|
|
|
var is_downloaded bool
|
|
|
for _, ep := range repoInfo.Index.Mirrors {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
|
if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
// Don't report errors when pulling from mirrors.
|
|
|
log.Debugf("Error pulling image (%s) from %s, mirror: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err)
|
|
@@ -202,12 +202,12 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
|
|
|
}
|
|
|
if !success {
|
|
|
for _, ep := range repoData.Endpoints {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, endpoint: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, endpoint: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
|
if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
// It's not ideal that only the last error is returned, it would be better to concatenate the errors.
|
|
|
// As the error is also given to the output stream the user will see the error.
|
|
|
lastErr = err
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err), nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), fmt.Sprintf("Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err), nil))
|
|
|
continue
|
|
|
}
|
|
|
layers_downloaded = layers_downloaded || is_downloaded
|
|
@@ -217,13 +217,13 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
|
|
|
}
|
|
|
if !success {
|
|
|
err := fmt.Errorf("Error pulling image (%s) from %s, %v", img.Tag, repoInfo.CanonicalName, lastErr)
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), err.Error(), nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), err.Error(), nil))
|
|
|
if parallel {
|
|
|
errors <- err
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Download complete", nil))
|
|
|
|
|
|
if parallel {
|
|
|
errors <- nil
|
|
@@ -270,7 +270,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(imgID), "Pulling dependent layers", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(imgID), "Pulling dependent layers", nil))
|
|
|
// FIXME: Try to stream the images?
|
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
|
|
|
@@ -286,7 +286,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
defer s.poolRemove("pull", "layer:"+id)
|
|
|
|
|
|
if !s.graph.Exists(id) {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Pulling metadata", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Pulling metadata", nil))
|
|
|
var (
|
|
|
imgJSON []byte
|
|
|
imgSize int
|
|
@@ -297,7 +297,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
for j := 1; j <= retries; j++ {
|
|
|
imgJSON, imgSize, err = r.GetRemoteImageJSON(id, endpoint, token)
|
|
|
if err != nil && j == retries {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
return layers_downloaded, err
|
|
|
} else if err != nil {
|
|
|
time.Sleep(time.Duration(j) * 500 * time.Millisecond)
|
|
@@ -306,7 +306,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
img, err = image.NewImgJSON(imgJSON)
|
|
|
layers_downloaded = true
|
|
|
if err != nil && j == retries {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
return layers_downloaded, fmt.Errorf("Failed to parse json: %s", err)
|
|
|
} else if err != nil {
|
|
|
time.Sleep(time.Duration(j) * 500 * time.Millisecond)
|
|
@@ -322,7 +322,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
if j > 1 {
|
|
|
status = fmt.Sprintf("Pulling fs layer [retries: %d]", j)
|
|
|
}
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), status, nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), status, nil))
|
|
|
layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token, int64(imgSize))
|
|
|
if uerr, ok := err.(*url.Error); ok {
|
|
|
err = uerr.Err
|
|
@@ -331,7 +331,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
time.Sleep(time.Duration(j) * 500 * time.Millisecond)
|
|
|
continue
|
|
|
} else if err != nil {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
return layers_downloaded, err
|
|
|
}
|
|
|
layers_downloaded = true
|
|
@@ -344,21 +344,21 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint
|
|
|
Formatter: sf,
|
|
|
Size: imgSize,
|
|
|
NewLines: false,
|
|
|
- ID: common.TruncateID(id),
|
|
|
+ ID: stringid.TruncateID(id),
|
|
|
Action: "Downloading",
|
|
|
}))
|
|
|
if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries {
|
|
|
time.Sleep(time.Duration(j) * 500 * time.Millisecond)
|
|
|
continue
|
|
|
} else if err != nil {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Error downloading dependent layers", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Error downloading dependent layers", nil))
|
|
|
return layers_downloaded, err
|
|
|
} else {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(id), "Download complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(id), "Download complete", nil))
|
|
|
}
|
|
|
return layers_downloaded, nil
|
|
|
}
|
|
@@ -478,16 +478,16 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
|
|
|
}
|
|
|
downloads[i].digest = dgst
|
|
|
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Pulling fs layer", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Pulling fs layer", nil))
|
|
|
|
|
|
downloadFunc := func(di *downloadInfo) error {
|
|
|
log.Debugf("pulling blob %q to V1 img %s", sumStr, img.ID)
|
|
|
|
|
|
if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
|
|
|
if c != nil {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil))
|
|
|
<-c
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Download complete", nil))
|
|
|
} else {
|
|
|
log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
|
|
|
}
|
|
@@ -515,20 +515,20 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
|
|
|
Formatter: sf,
|
|
|
Size: int(l),
|
|
|
NewLines: false,
|
|
|
- ID: common.TruncateID(img.ID),
|
|
|
+ ID: stringid.TruncateID(img.ID),
|
|
|
Action: "Downloading",
|
|
|
})); err != nil {
|
|
|
return fmt.Errorf("unable to copy v2 image blob data: %s", err)
|
|
|
}
|
|
|
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Verifying Checksum", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Verifying Checksum", nil))
|
|
|
|
|
|
if !verifier.Verified() {
|
|
|
log.Infof("Image verification failed: checksum mismatch for %q", di.digest.String())
|
|
|
verified = false
|
|
|
}
|
|
|
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Download complete", nil))
|
|
|
|
|
|
log.Debugf("Downloaded %s to tempfile %s", img.ID, tmpFile.Name())
|
|
|
di.tmpFile = tmpFile
|
|
@@ -574,7 +574,7 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
|
|
|
Out: out,
|
|
|
Formatter: sf,
|
|
|
Size: int(d.length),
|
|
|
- ID: common.TruncateID(d.img.ID),
|
|
|
+ ID: stringid.TruncateID(d.img.ID),
|
|
|
Action: "Extracting",
|
|
|
}))
|
|
|
if err != nil {
|
|
@@ -583,10 +583,10 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri
|
|
|
|
|
|
// FIXME: Pool release here for parallel tag pull (ensures any downloads block until fully extracted)
|
|
|
}
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Pull complete", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(d.img.ID), "Pull complete", nil))
|
|
|
tagUpdated = true
|
|
|
} else {
|
|
|
- out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Already exists", nil))
|
|
|
+ out.Write(sf.FormatProgress(stringid.TruncateID(d.img.ID), "Already exists", nil))
|
|
|
}
|
|
|
|
|
|
}
|