@@ -24,6 +24,7 @@ import (
2424 "net/http"
2525 "os"
2626 "path/filepath"
27+ "strings"
2728
2829 "github.com/opencontainers/go-digest"
2930 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -62,6 +63,10 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
6263 }
6364
6465 if parsedReference .Protocol != "" {
66+ if options .AllTags {
67+ return fmt .Errorf ("--all-tags is not supported for %q references" , parsedReference .Protocol )
68+ }
69+
6570 if parsedReference .Protocol != referenceutil .IPFSProtocol {
6671 return fmt .Errorf ("ipfs scheme is only supported but got %q" , parsedReference .Protocol )
6772 }
@@ -105,10 +110,42 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
105110 return nil
106111 }
107112
108- parsedReference , err = referenceutil .Parse (rawRef )
109- if err != nil {
110- return err
113+ if options .AllTags {
114+ repo := ""
115+ if parsedReference .Domain != "" {
116+ repo = parsedReference .Domain + "/"
117+ }
118+ repo += parsedReference .Path
119+
120+ imgList , err := client .ImageService ().List (ctx )
121+ if err != nil {
122+ return err
123+ }
124+
125+ var tagRefs []string
126+ for _ , img := range imgList {
127+ if strings .HasPrefix (img .Name , repo + ":" ) {
128+ tagRefs = append (tagRefs , img .Name )
129+ }
130+ }
131+
132+ if len (tagRefs ) == 0 {
133+ return fmt .Errorf ("no local tags found for repository %q" , repo )
134+ }
135+
136+ for i , tagRef := range tagRefs {
137+ tagOpts := options
138+ tagOpts .AllTags = false // avoid infinite recursion
139+ tagOpts .SkipSoci = i > 0 // avoid SOCI indexing for the same image
140+
141+ if err := Push (ctx , client , tagRef , tagOpts ); err != nil {
142+ return err
143+ }
144+ }
145+
146+ return nil
111147 }
148+
112149 ref := parsedReference .String ()
113150 refDomain := parsedReference .Domain
114151
@@ -209,7 +246,7 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
209246 options .SignOptions ); err != nil {
210247 return err
211248 }
212- if options .GOptions .Snapshotter == "soci" {
249+ if options .GOptions .Snapshotter == "soci" && ! options . SkipSoci {
213250 if err = snapshotterutil .CreateSociIndexV1 (ref , options .GOptions , options .AllPlatforms , options .Platforms , options .SociOptions ); err != nil {
214251 return err
215252 }
0 commit comments