Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions cmd/opm/alpha/bundle/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package bundle

import (
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
dirBuildArgs string
tagBuildArgs string
imageBuilderArgs string
packageNameArgs string
channelsArgs string
channelDefaultArgs string
overwriteArgs bool
)

// newBundleBuildCmd returns a command that will build operator bundle image.
func newBundleBuildCmd() *cobra.Command {
bundleBuildCmd := &cobra.Command{
Use: "build",
Short: "Build operator bundle image",
Long: `The "opm alpha bundle build" command will generate operator
bundle metadata if needed and build bundle image with operator manifest
and metadata.

For example: The command will generate annotations.yaml metadata plus
Dockerfile for bundle image and then build a container image from
provided operator bundle manifests generated metadata
e.g. "quay.io/example/operator:v0.0.1".

After the build process is completed, a container image would be built
locally in docker and available to push to a container registry.

$ opm alpha bundle build --directory /test/ --tag quay.io/example/operator:v0.1.0 \
--package test-operator --channels stable,beta --default stable --overwrite

Note: Bundle image is not runnable.
`,
RunE: buildFunc,
}

bundleBuildCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "", "The directory where bundle manifests and metadata are located")
if err := bundleBuildCmd.MarkFlagRequired("directory"); err != nil {
log.Fatalf("Failed to mark `directory` flag for `build` subcommand as required")
}

bundleBuildCmd.Flags().StringVarP(&tagBuildArgs, "tag", "t", "", "The image tag applied to the bundle image")
if err := bundleBuildCmd.MarkFlagRequired("tag"); err != nil {
log.Fatalf("Failed to mark `tag` flag for `build` subcommand as required")
}

bundleBuildCmd.Flags().StringVarP(&packageNameArgs, "package", "p", "", "The name of the package that bundle image belongs to")
if err := bundleBuildCmd.MarkFlagRequired("package"); err != nil {
log.Fatalf("Failed to mark `package` flag for `build` subcommand as required")
}

bundleBuildCmd.Flags().StringVarP(&channelsArgs, "channels", "c", "", "The list of channels that bundle image belongs to")
if err := bundleBuildCmd.MarkFlagRequired("channels"); err != nil {
log.Fatalf("Failed to mark `channels` flag for `build` subcommand as required")
}

bundleBuildCmd.Flags().StringVarP(&imageBuilderArgs, "image-builder", "b", "docker", "Tool to build container images. One of: [docker, podman, buildah]")

bundleBuildCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "", "The default channel for the bundle image")

bundleBuildCmd.Flags().BoolVarP(&overwriteArgs, "overwrite", "o", false, "To overwrite annotations.yaml locally if existed. By default, overwrite is set to `false`.")

return bundleBuildCmd
}

func buildFunc(cmd *cobra.Command, args []string) error {
err := bundle.BuildFunc(dirBuildArgs, tagBuildArgs, imageBuilderArgs,
packageNameArgs, channelsArgs, channelDefaultArgs, overwriteArgs)
if err != nil {
return err
}

return nil
}
17 changes: 17 additions & 0 deletions cmd/opm/alpha/bundle/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bundle

import (
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "bundle",
Short: "Operator bundle commands",
Long: `Generate operator bundle metadata and build bundle image.`,
}

runCmd.AddCommand(newBundleGenerateCmd())
runCmd.AddCommand(newBundleBuildCmd())
return runCmd
}
51 changes: 51 additions & 0 deletions cmd/opm/alpha/bundle/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package bundle

import (
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// newBundleGenerateCmd returns a command that will generate operator bundle
// annotations.yaml metadata
func newBundleGenerateCmd() *cobra.Command {
bundleGenerateCmd := &cobra.Command{
Use: "generate",
Short: "Generate operator bundle metadata and Dockerfile",
Long: `The "opm alpha bundle generate" command will generate operator
bundle metadata if needed and a Dockerfile to build Operator bundle image.

$ opm alpha bundle generate --directory /test/ --package test-operator \
--channels stable,beta --default stable
`,
RunE: generateFunc,
}

bundleGenerateCmd.Flags().StringVarP(&dirBuildArgs, "directory", "d", "", "The directory where bundle manifests are located.")
if err := bundleGenerateCmd.MarkFlagRequired("directory"); err != nil {
log.Fatalf("Failed to mark `directory` flag for `generate` subcommand as required")
}

bundleGenerateCmd.Flags().StringVarP(&packageNameArgs, "package", "p", "", "The name of the package that bundle image belongs to")
if err := bundleGenerateCmd.MarkFlagRequired("package"); err != nil {
log.Fatalf("Failed to mark `package` flag for `generate` subcommand as required")
}

bundleGenerateCmd.Flags().StringVarP(&channelsArgs, "channels", "c", "", "The list of channels that bundle image belongs to")
if err := bundleGenerateCmd.MarkFlagRequired("channels"); err != nil {
log.Fatalf("Failed to mark `channels` flag for `generate` subcommand as required")
}

bundleGenerateCmd.Flags().StringVarP(&channelDefaultArgs, "default", "e", "", "The default channel for the bundle image")

return bundleGenerateCmd
}

func generateFunc(cmd *cobra.Command, args []string) error {
err := bundle.GenerateFunc(dirBuildArgs, packageNameArgs, channelsArgs, channelDefaultArgs, true)
if err != nil {
return err
}

return nil
}
17 changes: 17 additions & 0 deletions cmd/opm/alpha/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package alpha

import (
"github.com/operator-framework/operator-registry/cmd/opm/alpha/bundle"
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
runCmd := &cobra.Command{
Hidden: true,
Use: "alpha",
Short: "Run an alpha subcommand",
}

runCmd.AddCommand(bundle.NewCmd())
return runCmd
}
17 changes: 16 additions & 1 deletion cmd/opm/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/cmd/opm/alpha"
"github.com/operator-framework/operator-registry/cmd/opm/registry"
)

Expand All @@ -12,11 +15,23 @@ func main() {
Use: "opm",
Short: "operator package manager",
Long: "CLI to interact with operator-registry and build indexes of operator content",
PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
},
}

rootCmd.AddCommand(registry.NewOpmRegistryCmd())
rootCmd.AddCommand(alpha.NewCmd())

if err := rootCmd.Execute(); err != nil {
rootCmd.Flags().Bool("debug", false, "enable debug logging")
if err := rootCmd.Flags().MarkHidden("debug"); err != nil {
logrus.Panic(err.Error())
}

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
Loading