mirror of https://github.com/docker/docs.git
Remove the pushImageRec and use iteration instead
This commit is contained in:
parent
c7a7983fcb
commit
55cf05835b
40
registry.go
40
registry.go
|
@ -393,14 +393,10 @@ func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, re
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pushImageRec(graph *Graph, stdout io.Writer, img *Image, registry string, token []string) error {
|
// Push a local image to the registry
|
||||||
if parent, err := img.GetParent(); err != nil {
|
func (graph *Graph) PushImage(stdout io.Writer, img *Image, registry string, token []string) error {
|
||||||
return err
|
registry = "https://" + registry + "/v1"
|
||||||
} else if parent != nil {
|
|
||||||
if err := pushImageRec(graph, stdout, parent, registry, token); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
client := graph.getHttpClient()
|
client := graph.getHttpClient()
|
||||||
jsonRaw, err := ioutil.ReadFile(path.Join(graph.Root, img.Id, "json"))
|
jsonRaw, err := ioutil.ReadFile(path.Join(graph.Root, img.Id, "json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -502,12 +498,6 @@ func pushImageRec(graph *Graph, stdout io.Writer, img *Image, registry string, t
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push a local image to the registry with its history if needed
|
|
||||||
func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, registry string, token []string) error {
|
|
||||||
registry = "https://" + registry + "/v1"
|
|
||||||
return pushImageRec(graph, stdout, imgOrig, registry, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
// push a tag on the registry.
|
// push a tag on the registry.
|
||||||
// Remote has the format '<user>/<repo>
|
// Remote has the format '<user>/<repo>
|
||||||
func (graph *Graph) pushTag(remote, revision, tag, registry string, token []string) error {
|
func (graph *Graph) pushTag(remote, revision, tag, registry string, token []string) error {
|
||||||
|
@ -626,14 +616,27 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re
|
||||||
client.Jar = cookiejar.NewCookieJar()
|
client.Jar = cookiejar.NewCookieJar()
|
||||||
var imgList []*ImgListJson
|
var imgList []*ImgListJson
|
||||||
|
|
||||||
|
fmt.Fprintf(stdout, "Processing checksums\n")
|
||||||
|
imageSet := make(map[string]struct{})
|
||||||
for _, id := range localRepo {
|
for _, id := range localRepo {
|
||||||
checksum, err := graph.getChecksum(id)
|
img, err := graph.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
imgList = append(imgList, &ImgListJson{
|
img.WalkHistory(func(img *Image) error {
|
||||||
Id: id,
|
if _, exists := imageSet[img.Id]; exists {
|
||||||
Checksum: checksum,
|
return nil
|
||||||
|
}
|
||||||
|
imageSet[img.Id] = struct{}{}
|
||||||
|
checksum, err := graph.getChecksum(img.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
imgList = append(imgList, &ImgListJson{
|
||||||
|
Id: img.Id,
|
||||||
|
Checksum: checksum,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,6 +647,7 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re
|
||||||
|
|
||||||
Debugf("json sent: %s\n", imgListJson)
|
Debugf("json sent: %s\n", imgListJson)
|
||||||
|
|
||||||
|
fmt.Fprintf(stdout, "Sending image list\n")
|
||||||
req, err := http.NewRequest("PUT", INDEX_ENDPOINT+"/repositories/"+remote+"/", bytes.NewReader(imgListJson))
|
req, err := http.NewRequest("PUT", INDEX_ENDPOINT+"/repositories/"+remote+"/", bytes.NewReader(imgListJson))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue