github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/manifest_create.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/spf13/cobra" 8 9 "github.com/buildpacks/pack/pkg/client" 10 "github.com/buildpacks/pack/pkg/logging" 11 ) 12 13 // ManifestCreateFlags define flags provided to the ManifestCreate 14 type ManifestCreateFlags struct { 15 format string 16 insecure, publish bool 17 } 18 19 // ManifestCreate creates an image index for a multi-arch image 20 func ManifestCreate(logger logging.Logger, pack PackClient) *cobra.Command { 21 var flags ManifestCreateFlags 22 23 cmd := &cobra.Command{ 24 Use: "create <manifest-list> <manifest> [<manifest> ... ] [flags]", 25 Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs), 26 Short: "Create a new manifest list.", 27 Example: `pack manifest create my-image-index my-image:some-arch my-image:some-other-arch`, 28 Long: `Create a new manifest list (e.g., for multi-arch images) which will be stored locally for manipulating images within the index`, 29 RunE: logError(logger, func(cmd *cobra.Command, args []string) error { 30 format, err := parseFormatFlag(strings.ToLower(flags.format)) 31 if err != nil { 32 return err 33 } 34 35 if err = validateCreateManifestFlags(flags); err != nil { 36 return err 37 } 38 39 return pack.CreateManifest( 40 cmd.Context(), 41 client.CreateManifestOptions{ 42 IndexRepoName: args[0], 43 RepoNames: args[1:], 44 Format: format, 45 Insecure: flags.insecure, 46 Publish: flags.publish, 47 }, 48 ) 49 }), 50 } 51 52 cmdFlags := cmd.Flags() 53 54 cmdFlags.StringVarP(&flags.format, "format", "f", "oci", "Media type to use when saving the image index. Accepted values are: oci, docker") 55 cmdFlags.BoolVar(&flags.insecure, "insecure", false, "When pushing the index to a registry, do not use TLS encryption or certificate verification; use with --publish") 56 cmdFlags.BoolVar(&flags.publish, "publish", false, "Publish directly to a registry without saving a local copy") 57 58 AddHelpFlag(cmd, "create") 59 return cmd 60 } 61 62 func validateCreateManifestFlags(flags ManifestCreateFlags) error { 63 if flags.insecure && !flags.publish { 64 return fmt.Errorf("insecure flag requires the publish flag") 65 } 66 return nil 67 }