Merge pull request #3995 from deitch/cache-push-options

push arch-specific tags optional
This commit is contained in:
Avi Deitcher 2024-03-01 04:50:10 -08:00 committed by GitHub
commit 58c36c9eb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 36 deletions

View File

@ -15,7 +15,10 @@ import (
// Push push an image along with a multi-arch index.
// name is the name as referenced in the local cache, remoteName is the name to give it remotely.
// If remoteName is empty, it is the same as name.
func (p *Provider) Push(name, remoteName string, withManifest bool) error {
// If withArchSpecificTags is true, it will push all arch-specific images in the index, each as
// their own tag with the same name as the index, but with the architecture appended, e.g.
// image:foo will have image:foo-amd64, image:foo-arm64, etc.
func (p *Provider) Push(name, remoteName string, withArchSpecificTags bool) error {
var (
err error
options []remote.Option
@ -89,7 +92,8 @@ func (p *Provider) Push(name, remoteName string, withManifest bool) error {
return err
}
fmt.Printf("Pushed index %s\n", name)
log.Debugf("pushing individual images in the index %s", name)
if withArchSpecificTags {
fmt.Printf("pushing individual images in the index %s", name)
for _, m := range manifest.Manifests {
if m.Platform == nil || m.Platform.Architecture == "" {
continue
@ -126,6 +130,9 @@ func (p *Provider) Push(name, remoteName string, withManifest bool) error {
return fmt.Errorf("error creating tag %s: %v", archTag, err)
}
}
} else {
fmt.Printf("Skipping push of individual images in the index %s\n", name)
}
default:
return fmt.Errorf("name %s unknown in cache", name)
}

View File

@ -8,7 +8,10 @@ import (
)
func cachePushCmd() *cobra.Command {
var remoteName string
var (
remoteName string
pushArchSpecificTags bool
)
cmd := &cobra.Command{
Use: "push",
Short: "push images from the linuxkit cache",
@ -26,7 +29,7 @@ func cachePushCmd() *cobra.Command {
log.Fatalf("unable to read a local cache: %v", err)
}
if err := p.Push(fullname, remoteName, true); err != nil {
if err := p.Push(fullname, remoteName, pushArchSpecificTags); err != nil {
log.Fatalf("unable to push image named %s: %v", name, err)
}
}
@ -34,6 +37,6 @@ func cachePushCmd() *cobra.Command {
},
}
cmd.Flags().StringVar(&remoteName, "remote-name", "", "Push it under a different name, e.g. push local image foo/bar:mine as baz/bee:yours. If blank, uses same local name.")
cmd.Flags().BoolVar(&pushArchSpecificTags, "with-arch-tags", false, "When the local reference is an index, add to the remote arch-specific tags for each arch in the index, each as their own tag with the same name as the index, but with the architecture appended, e.g. image:foo will have image:foo-amd64, image:foo-arm64, etc.")
return cmd
}