diff --git a/src/cmd/linuxkit/cache/push.go b/src/cmd/linuxkit/cache/push.go index aeaca0de5..c00c863ea 100644 --- a/src/cmd/linuxkit/cache/push.go +++ b/src/cmd/linuxkit/cache/push.go @@ -29,16 +29,38 @@ func (p *Provider) Push(name string) error { return err } options = append(options, remote.WithAuthFromKeychain(authn.DefaultKeychain)) + img, err1 := root.Image() ii, err2 := root.ImageIndex() + // before we even try to push, let us see if it exists remotely + remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)} + switch { case err1 == nil: + dig, err := img.Digest() + if err != nil { + return fmt.Errorf("could not get digest for image %s: %v", name, err) + } + desc, err := remote.Get(ref, remoteOptions...) + if err == nil && desc != nil && dig == desc.Digest { + fmt.Printf("%s image already available on remote registry, skipping push", name) + return nil + } log.Debugf("pushing image %s", name) if err := remote.Write(ref, img, options...); err != nil { return err } fmt.Printf("Pushed image %s\n", name) case err2 == nil: + dig, err := ii.Digest() + if err != nil { + return fmt.Errorf("could not get digest for index %s: %v", name, err) + } + desc, err := remote.Get(ref, remoteOptions...) + if err == nil && desc != nil && dig == desc.Digest { + fmt.Printf("%s index already available on remote registry, skipping push", name) + return nil + } log.Debugf("pushing index %s", name) // this is an index, so we not only want to write the index, but tags for each arch-specific image in it if err := remote.WriteIndex(ref, ii, options...); err != nil { diff --git a/src/cmd/linuxkit/pkg_build.go b/src/cmd/linuxkit/pkg_build.go index d6fda1029..141774f9a 100644 --- a/src/cmd/linuxkit/pkg_build.go +++ b/src/cmd/linuxkit/pkg_build.go @@ -158,6 +158,14 @@ func pkgBuildPush(args []string, withPush bool) { pkgPlats = append(pkgPlats, imagespec.Platform{OS: "linux", Architecture: a}) } } + + // if there are no platforms to build for, do nothing. + // note that this is *not* an error; we simply skip it + if len(pkgPlats) == 0 { + fmt.Printf("Skipping %s with no architectures to build\n", p.Tag()) + return + } + pkgOpts = append(pkgOpts, pkglib.WithBuildPlatforms(pkgPlats...)) var msg, action string