2017-06-15 14:41:54 -04:00
|
|
|
package manifest
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2017-06-15 14:41:54 -04:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/manifest/store"
|
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type createOpts struct {
|
|
|
|
amend bool
|
|
|
|
insecure bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCreateListCommand(dockerCli command.Cli) *cobra.Command {
|
|
|
|
opts := createOpts{}
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2018-04-01 10:34:58 -04:00
|
|
|
Use: "create MANIFEST_LIST MANIFEST [MANIFEST...]",
|
2017-06-15 14:41:54 -04:00
|
|
|
Short: "Create a local manifest list for annotating and pushing to a registry",
|
|
|
|
Args: cli.RequiresMinArgs(2),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2023-09-09 18:27:44 -04:00
|
|
|
return createManifestList(cmd.Context(), dockerCli, args, opts)
|
2017-06-15 14:41:54 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags := cmd.Flags()
|
2018-04-24 09:00:39 -04:00
|
|
|
flags.BoolVar(&opts.insecure, "insecure", false, "Allow communication with an insecure registry")
|
2017-06-15 14:41:54 -04:00
|
|
|
flags.BoolVarP(&opts.amend, "amend", "a", false, "Amend an existing manifest list")
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-09-09 18:27:44 -04:00
|
|
|
func createManifestList(ctx context.Context, dockerCli command.Cli, args []string, opts createOpts) error {
|
2017-06-15 14:41:54 -04:00
|
|
|
newRef := args[0]
|
|
|
|
targetRef, err := normalizeReference(newRef)
|
|
|
|
if err != nil {
|
2017-09-26 18:15:04 -04:00
|
|
|
return errors.Wrapf(err, "error parsing name for manifest list %s", newRef)
|
2017-06-15 14:41:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = registry.ParseRepositoryInfo(targetRef)
|
|
|
|
if err != nil {
|
2017-09-26 18:15:04 -04:00
|
|
|
return errors.Wrapf(err, "error parsing repository name for manifest list %s", newRef)
|
2017-06-15 14:41:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
manifestStore := dockerCli.ManifestStore()
|
|
|
|
_, err = manifestStore.GetList(targetRef)
|
|
|
|
switch {
|
|
|
|
case store.IsNotFound(err):
|
|
|
|
// New manifest list
|
|
|
|
case err != nil:
|
|
|
|
return err
|
|
|
|
case !opts.amend:
|
|
|
|
return errors.Errorf("refusing to amend an existing manifest list with no --amend flag")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now create the local manifest list transaction by looking up the manifest schemas
|
|
|
|
// for the constituent images:
|
|
|
|
manifests := args[1:]
|
|
|
|
for _, manifestRef := range manifests {
|
|
|
|
namedRef, err := normalizeReference(manifestRef)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: wrap error?
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest, err := getManifest(ctx, dockerCli, targetRef, namedRef, opts.insecure)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := manifestStore.Save(targetRef, namedRef, manifest); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintf(dockerCli.Out(), "Created manifest list %s\n", targetRef.String())
|
|
|
|
return nil
|
|
|
|
}
|