github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/client/manifest_push.go (about) 1 package client 2 3 import ( 4 "fmt" 5 6 "github.com/buildpacks/imgutil" 7 "github.com/google/go-containerregistry/pkg/v1/types" 8 9 "github.com/buildpacks/pack/internal/style" 10 ) 11 12 type PushManifestOptions struct { 13 // Image index we want to update 14 IndexRepoName string 15 16 // Index media-type 17 Format types.MediaType 18 19 // true if we want to publish to an insecure registry 20 Insecure bool 21 22 // true if we want the index to be deleted from local storage after pushing it 23 Purge bool 24 } 25 26 // PushManifest implements commands.PackClient. 27 func (c *Client) PushManifest(opts PushManifestOptions) (err error) { 28 if opts.Format == "" { 29 opts.Format = types.OCIImageIndex 30 } 31 ops := parseOptions(opts) 32 33 idx, err := c.indexFactory.LoadIndex(opts.IndexRepoName) 34 if err != nil { 35 return 36 } 37 38 if err = idx.Push(ops...); err != nil { 39 return fmt.Errorf("failed to push manifest list %s: %w", style.Symbol(opts.IndexRepoName), err) 40 } 41 42 if !opts.Purge { 43 c.logger.Infof("Successfully pushed manifest list %s to registry", style.Symbol(opts.IndexRepoName)) 44 return nil 45 } 46 47 return idx.DeleteDir() 48 } 49 50 func parseOptions(opts PushManifestOptions) (idxOptions []imgutil.IndexOption) { 51 if opts.Insecure { 52 idxOptions = append(idxOptions, imgutil.WithInsecure()) 53 } 54 55 if opts.Purge { 56 idxOptions = append(idxOptions, imgutil.WithPurge(true)) 57 } 58 59 return append(idxOptions, imgutil.WithMediaType(opts.Format)) 60 }