Merge pull request #3787 from deitch/skip-build-if-no-platforms

This commit is contained in:
Avi Deitcher 2022-06-07 13:24:59 +03:00 committed by GitHub
commit b56a0df58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -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 {

View File

@ -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