Skip to content

Commit

Permalink
Add flag for using opm alpha to generate dockerfile instead of opm ge…
Browse files Browse the repository at this point in the history
…nerate
  • Loading branch information
shanedell committed Jan 17, 2024
1 parent bc559d5 commit ff552bc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
9 changes: 9 additions & 0 deletions cmd/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
opmVersion string
targetImage string
folderName string
useAlpha bool
)

var pruneHelp = "prune the Red Hat Operator index image"
Expand Down Expand Up @@ -77,6 +78,13 @@ func NewPruneCommand() *cobra.Command {
"folder name for the pruned catalog",
)

pruneCommand.PersistentFlags().BoolVar(
&useAlpha,
"use-alpha",
false,
"use opm alpha to generate dockerfile instead of opm generate",
)

return pruneCommand
}

Expand All @@ -102,6 +110,7 @@ func pruneMain(_ *cobra.Command, _ []string) error {
OpmVersion: opmVersion,
TargetImage: targetImage,
FolderName: folderName,
UseAlpha: useAlpha,
}

return app.PruneIndexImage(
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
)

require (
github.com/blang/semver/v4 v4.0.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
31 changes: 22 additions & 9 deletions pkg/app/prune_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,26 @@ func createIndexFile(imageToPrune string, osName string, jqArgs string, prunedCa
return nil
}

func createDockerFile(containerRuntimePath string, osName string, prunedCatalogFolder string) error {
cmd := utils.CreateCommand(
filepath.Join(utils.BundleDirs.Bin, "opm"),
"alpha",
"generate",
"dockerfile",
prunedCatalogFolder,
)
func createDockerFile(containerRuntimePath string, osName string, prunedCatalogFolder string, useAlpha bool) error {
var params []string

if useAlpha {
params = []string{
"alpha",
"generate",
"dockerfile",
prunedCatalogFolder,
}
} else {
params = []string{
"generate",
"dockerfile",
prunedCatalogFolder,
}
}

cmd := utils.CreateCommand(filepath.Join(utils.BundleDirs.Bin, "opm"), params...)

return runOpmCommand(cmd, osName, containerRuntimePath, true)
}

Expand Down Expand Up @@ -85,7 +97,8 @@ func pruneFile(pruneData *utils.PruneDataType, containerRuntime string, containe
utils.Logger.Info("Finished creating index file...")

utils.Logger.Info("Creating dockerfile...")
err = createDockerFile(containerRuntimePath, osName, prunedCatalogFolder)

err = createDockerFile(containerRuntimePath, osName, prunedCatalogFolder, pruneData.UseAlpha)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ type PruneDataType struct {
PruneType string
TargetImage string
FolderName string
UseAlpha bool
}

0 comments on commit ff552bc

Please sign in to comment.