add ability to just update manifest

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2022-07-26 19:36:31 +03:00
parent 239d4d9502
commit b28621b95a
3 changed files with 104 additions and 0 deletions

View File

@ -32,6 +32,10 @@ func pkg(args []string) {
pkgPush(args[1:])
case "show-tag":
pkgShowTag(args[1:])
case "manifest":
pkgManifest(args[1:])
case "index":
pkgIndex(args[1:])
default:
fmt.Printf("Unknown subcommand %q\n\n", args[0])
pkgUsage()

View File

@ -0,0 +1,50 @@
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkglib"
)
func pkgManifest(args []string) {
pkgIndex(args)
}
func pkgIndex(args []string) {
flags := flag.NewFlagSet("pkg manifest", flag.ExitOnError)
flags.Usage = func() {
invoked := filepath.Base(os.Args[0])
name := "manifest"
fmt.Fprintf(os.Stderr, "USAGE: %s pkg %s [options] path\n\n", name, invoked)
fmt.Fprintf(os.Stderr, "'path' specifies the path to the package source directory.\n")
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Updates the manifest in the registry for the given path based on all known platforms. If none found, no manifest created.\n")
flags.PrintDefaults()
}
release := flags.String("release", "", "Release the given version")
pkgs, err := pkglib.NewFromCLI(flags, args...)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
var opts []pkglib.BuildOpt
if *release != "" {
opts = append(opts, pkglib.WithRelease(*release))
}
for _, p := range pkgs {
msg := fmt.Sprintf("Updating index for %q", p.Tag())
action := "building and pushing"
fmt.Println(msg)
if err := p.Index(opts...); err != nil {
fmt.Fprintf(os.Stderr, "Error %s %q: %v\n", action, p.Tag(), err)
os.Exit(1)
}
}
}

View File

@ -0,0 +1,50 @@
package pkglib
import (
"fmt"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/registry"
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
)
// Index create an index for the package tag based on all arch-specific tags in the registry.
func (p Pkg) Index(bos ...BuildOpt) error {
var bo buildOpts
for _, fn := range bos {
if err := fn(&bo); err != nil {
return err
}
}
name := p.FullTag()
// Even though we may have pushed the index, we want to be sure that we have an index that includes every architecture on the registry,
// not just those that were in our local cache. So we use manifest-tool library to build a broad index
auth, err := registry.GetDockerAuth()
if err != nil {
return fmt.Errorf("failed to get auth: %v", err)
}
// push based on tag
fmt.Printf("Pushing index based on all arch-specific images in registry %s\n", name)
_, _, err = registry.PushManifest(name, auth)
if err != nil {
return err
}
// push based on release
if bo.release != "" {
relTag, err := p.ReleaseTag(bo.release)
if err != nil {
return err
}
fullRelTag := util.ReferenceExpand(relTag)
fmt.Printf("Pushing index based on all arch-specific images in registry %s\n", fullRelTag)
_, _, err = registry.PushManifest(fullRelTag, auth)
if err != nil {
return err
}
}
return nil
}