|
@@ -145,7 +145,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
|
|
|
|
- if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("Downloading", "%8v/%v (%v)"), sf), path); err != nil {
|
|
|
|
|
|
+ if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("", "Downloading", "%8v/%v (%v)"), sf), path); err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
// FIXME: Handle custom repo, tag comment, author
|
|
// FIXME: Handle custom repo, tag comment, author
|
|
@@ -153,7 +153,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus(img.ID))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", img.ID))
|
|
return img.ShortID(), nil
|
|
return img.ShortID(), nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -420,7 +420,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
for _, id := range history {
|
|
for _, id := range history {
|
|
if !srv.runtime.graph.Exists(id) {
|
|
if !srv.runtime.graph.Exists(id) {
|
|
- out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(id), "Pulling metadata"))
|
|
imgJSON, imgSize, err := r.GetRemoteImageJSON(id, endpoint, token)
|
|
imgJSON, imgSize, err := r.GetRemoteImageJSON(id, endpoint, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
// FIXME: Keep goging in case of error?
|
|
// FIXME: Keep goging in case of error?
|
|
@@ -432,13 +432,13 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
}
|
|
}
|
|
|
|
|
|
// Get the layer
|
|
// Get the layer
|
|
- out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(id), "Pulling fs layer"))
|
|
layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token)
|
|
layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
defer layer.Close()
|
|
defer layer.Close()
|
|
- if err := srv.runtime.graph.Register(imgJSON, utils.ProgressReader(layer, imgSize, out, sf.FormatProgress("Downloading", "%8v/%v (%v)"), sf), img); err != nil {
|
|
|
|
|
|
+ if err := srv.runtime.graph.Register(imgJSON, utils.ProgressReader(layer, imgSize, out, sf.FormatProgress(utils.TruncateID(id), "Downloading", "%8v/%v (%v)"), sf), img); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -446,8 +446,8 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter) error {
|
|
|
|
- out.Write(sf.FormatStatus("Pulling repository %s", localName))
|
|
|
|
|
|
+func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter, parallel bool) error {
|
|
|
|
+ out.Write(sf.FormatStatus("", "Pulling repository %s", localName))
|
|
|
|
|
|
repoData, err := r.GetRepositoryData(indexEp, remoteName)
|
|
repoData, err := r.GetRepositoryData(indexEp, remoteName)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -484,30 +484,51 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName
|
|
repoData.ImgList[id].Tag = askedTag
|
|
repoData.ImgList[id].Tag = askedTag
|
|
}
|
|
}
|
|
|
|
|
|
- for _, img := range repoData.ImgList {
|
|
|
|
- if askedTag != "" && img.Tag != askedTag {
|
|
|
|
- utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
|
|
|
- continue
|
|
|
|
|
|
+ errors := make(chan error)
|
|
|
|
+ for _, image := range repoData.ImgList {
|
|
|
|
+ downloadImage := func(img *registry.ImgData) {
|
|
|
|
+ if askedTag != "" && img.Tag != askedTag {
|
|
|
|
+ utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
|
|
|
+ errors <- nil
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if img.Tag == "" {
|
|
|
|
+ utils.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
|
|
|
|
+ errors <- nil
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(img.ID), "Pulling image (%s) from %s", img.Tag, localName))
|
|
|
|
+ success := false
|
|
|
|
+ for _, ep := range repoData.Endpoints {
|
|
|
|
+ if err := srv.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(img.ID), "Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ success = true
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ if !success {
|
|
|
|
+ errors <- fmt.Errorf("Could not find repository on any of the indexed registries.")
|
|
|
|
+ }
|
|
|
|
+ errors <- nil
|
|
}
|
|
}
|
|
|
|
|
|
- if img.Tag == "" {
|
|
|
|
- utils.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
|
|
|
|
- continue
|
|
|
|
|
|
+ if parallel {
|
|
|
|
+ go downloadImage(image)
|
|
|
|
+ } else {
|
|
|
|
+ downloadImage(image)
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.ID, img.Tag, localName))
|
|
|
|
- success := false
|
|
|
|
- for _, ep := range repoData.Endpoints {
|
|
|
|
- if err := srv.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
|
- out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
|
|
|
- continue
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if parallel {
|
|
|
|
+ for i := 0; i < len(repoData.ImgList); i++ {
|
|
|
|
+ if err := <-errors; err != nil {
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
- success = true
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- if !success {
|
|
|
|
- return fmt.Errorf("Could not find repository on any of the indexed registries.")
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
for tag, id := range tagsList {
|
|
for tag, id := range tagsList {
|
|
if askedTag != "" && tag != askedTag {
|
|
if askedTag != "" && tag != askedTag {
|
|
continue
|
|
continue
|
|
@@ -558,7 +579,7 @@ func (srv *Server) poolRemove(kind, key string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
|
|
|
|
|
|
+func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig, parallel bool) error {
|
|
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory())
|
|
r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory())
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -580,7 +601,7 @@ func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *ut
|
|
}
|
|
}
|
|
|
|
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
- err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf)
|
|
|
|
|
|
+ err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf, parallel)
|
|
if err != nil {
|
|
if err != nil {
|
|
if err := srv.pullImage(r, out, remoteName, endpoint, nil, sf); err != nil {
|
|
if err := srv.pullImage(r, out, remoteName, endpoint, nil, sf); err != nil {
|
|
return err
|
|
return err
|
|
@@ -620,12 +641,11 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
|
|
|
|
func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName, remoteName string, localRepo map[string]string, indexEp string, sf *utils.StreamFormatter) error {
|
|
func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName, remoteName string, localRepo map[string]string, indexEp string, sf *utils.StreamFormatter) error {
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
-
|
|
|
|
imgList, err := srv.getImageList(localRepo)
|
|
imgList, err := srv.getImageList(localRepo)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus("Sending image list"))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Sending image list"))
|
|
|
|
|
|
var repoData *registry.RepositoryData
|
|
var repoData *registry.RepositoryData
|
|
repoData, err = r.PushImageJSONIndex(indexEp, remoteName, imgList, false, nil)
|
|
repoData, err = r.PushImageJSONIndex(indexEp, remoteName, imgList, false, nil)
|
|
@@ -634,14 +654,14 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
|
|
}
|
|
}
|
|
|
|
|
|
for _, ep := range repoData.Endpoints {
|
|
for _, ep := range repoData.Endpoints {
|
|
- out.Write(sf.FormatStatus("Pushing repository %s (%d tags)", localName, len(localRepo)))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing repository %s (%d tags)", localName, len(localRepo)))
|
|
// For each image within the repo, push them
|
|
// For each image within the repo, push them
|
|
for _, elem := range imgList {
|
|
for _, elem := range imgList {
|
|
if _, exists := repoData.ImgList[elem.ID]; exists {
|
|
if _, exists := repoData.ImgList[elem.ID]; exists {
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", elem.ID))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", elem.ID))
|
|
continue
|
|
continue
|
|
} else if r.LookupRemoteImage(elem.ID, ep, repoData.Tokens) {
|
|
} else if r.LookupRemoteImage(elem.ID, ep, repoData.Tokens) {
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", elem.ID))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", elem.ID))
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if checksum, err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
if checksum, err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
@@ -650,7 +670,7 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
|
|
} else {
|
|
} else {
|
|
elem.Checksum = checksum
|
|
elem.Checksum = checksum
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"repositories/"+remoteName+"/tags/"+elem.Tag))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing tags for rev [%s] on {%s}", elem.ID, ep+"repositories/"+remoteName+"/tags/"+elem.Tag))
|
|
if err := r.PushRegistryTag(remoteName, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
if err := r.PushRegistryTag(remoteName, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -670,7 +690,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", fmt.Errorf("Error while retreiving the path for {%s}: %s", imgID, err)
|
|
return "", fmt.Errorf("Error while retreiving the path for {%s}: %s", imgID, err)
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus("Pushing %s", imgID))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing %s", imgID))
|
|
|
|
|
|
imgData := ®istry.ImgData{
|
|
imgData := ®istry.ImgData{
|
|
ID: imgID,
|
|
ID: imgID,
|
|
@@ -679,7 +699,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
|
// Send the json
|
|
// Send the json
|
|
if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
if err == registry.ErrAlreadyExists {
|
|
if err == registry.ErrAlreadyExists {
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", imgData.ID))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", imgData.ID))
|
|
return "", nil
|
|
return "", nil
|
|
}
|
|
}
|
|
return "", err
|
|
return "", err
|
|
@@ -691,7 +711,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
|
}
|
|
}
|
|
|
|
|
|
// Send the layer
|
|
// Send the layer
|
|
- if checksum, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("Pushing", "%8v/%v (%v)"), sf), ep, token, jsonRaw); err != nil {
|
|
|
|
|
|
+ if checksum, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "Pushing", "%8v/%v (%v)"), sf), ep, token, jsonRaw); err != nil {
|
|
return "", err
|
|
return "", err
|
|
} else {
|
|
} else {
|
|
imgData.Checksum = checksum
|
|
imgData.Checksum = checksum
|
|
@@ -727,7 +747,7 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
reposLen := len(srv.runtime.repositories.Repositories[localName])
|
|
reposLen := len(srv.runtime.repositories.Repositories[localName])
|
|
- out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", localName, reposLen))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "The push refers to a repository [%s] (len: %d)", localName, reposLen))
|
|
// If it fails, try to get the repository
|
|
// If it fails, try to get the repository
|
|
if localRepo, exists := srv.runtime.repositories.Repositories[localName]; exists {
|
|
if localRepo, exists := srv.runtime.repositories.Repositories[localName]; exists {
|
|
if err := srv.pushRepository(r, out, localName, remoteName, localRepo, endpoint, sf); err != nil {
|
|
if err := srv.pushRepository(r, out, localName, remoteName, localRepo, endpoint, sf); err != nil {
|
|
@@ -739,7 +759,7 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
|
|
}
|
|
}
|
|
|
|
|
|
var token []string
|
|
var token []string
|
|
- out.Write(sf.FormatStatus("The push refers to an image: [%s]", localName))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "The push refers to an image: [%s]", localName))
|
|
if _, err := srv.pushImage(r, out, remoteName, img.ID, endpoint, token, sf); err != nil {
|
|
if _, err := srv.pushImage(r, out, remoteName, img.ID, endpoint, token, sf); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -762,14 +782,14 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
u.Host = src
|
|
u.Host = src
|
|
u.Path = ""
|
|
u.Path = ""
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus("Downloading from %s", u))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", "Downloading from %s", u))
|
|
// Download with curl (pretty progress bar)
|
|
// Download with curl (pretty progress bar)
|
|
// If curl is not available, fallback to http.Get()
|
|
// If curl is not available, fallback to http.Get()
|
|
resp, err = utils.Download(u.String(), out)
|
|
resp, err = utils.Download(u.String(), out)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("Importing", "%8v/%v (%v)"), sf)
|
|
|
|
|
|
+ archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("", "Importing", "%8v/%v (%v)"), sf)
|
|
}
|
|
}
|
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -781,7 +801,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- out.Write(sf.FormatStatus(img.ShortID()))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("", img.ShortID()))
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|