@@ -95,7 +95,9 @@ func (graph *Graph) getImagesInRepository(repository string, authConfig *auth.Au
9595 if err != nil {
9696 return nil , err
9797 }
98- req .SetBasicAuth (authConfig .Username , authConfig .Password )
98+ if authConfig != nil && len (authConfig .Username ) > 0 {
99+ req .SetBasicAuth (authConfig .Username , authConfig .Password )
100+ }
99101 res , err := graph .getHttpClient ().Do (req )
100102 if err != nil {
101103 return nil , err
@@ -111,9 +113,12 @@ func (graph *Graph) getImagesInRepository(repository string, authConfig *auth.Au
111113 if err != nil {
112114 return nil , err
113115 }
116+
114117 imageList := []map [string ]string {}
118+
115119 err = json .Unmarshal (jsonData , & imageList )
116120 if err != nil {
121+ Debugf ("Body: %s (%s)\n " , res .Body , u )
117122 return nil , err
118123 }
119124
@@ -174,7 +179,7 @@ func (graph *Graph) getRemoteTags(stdout io.Writer, registries []string, reposit
174179 repository = "library/" + repository
175180 }
176181 for _ , host := range registries {
177- endpoint := "https://" + host + " /v1/repositories/" + repository + "/tags"
182+ endpoint := fmt . Sprintf ( "https://%s /v1/repositories/%s/tags" , host , repository )
178183 req , err := http .NewRequest ("GET" , endpoint , nil )
179184 if err != nil {
180185 return nil , err
@@ -433,12 +438,6 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, registry string,
433438// push a tag on the registry.
434439// Remote has the format '<user>/<repo>
435440func (graph * Graph ) pushTag (remote , revision , tag , registry string , token []string ) error {
436-
437- // Keep this for backward compatibility
438- if tag == "" {
439- tag = "lastest"
440- }
441-
442441 // "jsonify" the string
443442 revision = "\" " + revision + "\" "
444443 registry = "https://" + registry + "/v1"
@@ -490,16 +489,17 @@ func (graph *Graph) pushPrimitive(stdout io.Writer, remote, tag, imgId, registry
490489func (graph * Graph ) PushRepository (stdout io.Writer , remote string , localRepo Repository , authConfig * auth.AuthConfig ) error {
491490 client := graph .getHttpClient ()
492491
493- checksums , err := graph .Checksums (localRepo )
494- imgList := make ([]map [string ]string , len (checksums ))
495- checksums2 := make ([]map [string ]string , len (checksums ))
492+ checksums , err := graph .Checksums (stdout , localRepo )
496493 if err != nil {
497494 return err
498495 }
499496
497+ imgList := make ([]map [string ]string , len (checksums ))
498+ checksums2 := make ([]map [string ]string , len (checksums ))
499+
500500 uploadedImages , err := graph .getImagesInRepository (remote , authConfig )
501501 if err != nil {
502- return fmt .Errorf ("Error occured while fetching the list: %v " , err )
502+ return fmt .Errorf ("Error occured while fetching the list: %s " , err )
503503 }
504504
505505 // Filter list to only send images/checksums not already uploaded
@@ -605,3 +605,37 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re
605605
606606 return nil
607607}
608+
609+ func (graph * Graph ) Checksums (output io.Writer , repo Repository ) ([]map [string ]string , error ) {
610+ var result []map [string ]string
611+ checksums := map [string ]string {}
612+ for _ , id := range repo {
613+ img , err := graph .Get (id )
614+ if err != nil {
615+ return nil , err
616+ }
617+ err = img .WalkHistory (func (image * Image ) error {
618+ fmt .Fprintf (output , "Computing checksum for image %s\n " , image .Id )
619+ if _ , exists := checksums [image .Id ]; ! exists {
620+ checksums [image .Id ], err = image .Checksum ()
621+ if err != nil {
622+ return err
623+ }
624+ }
625+ return nil
626+ })
627+ if err != nil {
628+ return nil , err
629+ }
630+ }
631+ i := 0
632+ result = make ([]map [string ]string , len (checksums ))
633+ for id , sum := range checksums {
634+ result [i ] = map [string ]string {
635+ "id" : id ,
636+ "checksum" : sum ,
637+ }
638+ i ++
639+ }
640+ return result , nil
641+ }
0 commit comments