Skip to content

Commit

Permalink
Add missing tool version commands
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Zaneski <eddiezane@defenseunicorns.com>
  • Loading branch information
eddiezane committed Jan 18, 2024
1 parent 0866000 commit ce85228
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.
K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1)))
K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER))
K8S_MODULES_PATCH_VER=$(word 3,$(K8S_MODULES_VER))
K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s)
CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry)
SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft)
ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3)
HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3)

BUILD_ARGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
BUILD_ARGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
BUILD_ARGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER)
BUILD_ARGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$(K8S_MODULES_MINOR_VER)
BUILD_ARGS += -X k8s.io/component-base/version.gitVersion=v$(K8S_MODULES_MAJOR_VER).$(K8S_MODULES_MINOR_VER).$(K8S_MODULES_PATCH_VER)
BUILD_ARGS += -X github.com/derailed/k9s/cmd.version=$(K9S_VERSION)
BUILD_ARGS += -X github.com/google/go-containerregistry/cmd/crane/cmd.Version=$(CRANE_VERSION)
BUILD_ARGS += -X github.com/defenseunicorns/zarf/src/cmd/tools.syftVersion=$(SYFT_VERSION)
BUILD_ARGS += -X github.com/defenseunicorns/zarf/src/cmd/tools.archiverVersion=$(ARCHIVER_VERSION)
BUILD_ARGS += -X github.com/defenseunicorns/zarf/src/cmd/tools.helmVersion=$(HELM_VERSION)

GIT_SHA := $(if $(shell git rev-parse HEAD),$(shell git rev-parse HEAD),"")
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/tools/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import (
"github.com/spf13/cobra"
)

// ldflags github.com/defenseunicorns/zarf/src/cmd/tools.archiverVersion=x.x.x
var archiverVersion string

var archiverCmd = &cobra.Command{
Use: "archiver",
Aliases: []string{"a"},
Short: lang.CmdToolsArchiverShort,
Version: archiverVersion,
}

var archiverCompressCmd = &cobra.Command{
Expand Down Expand Up @@ -85,6 +89,7 @@ func init() {

archiverCmd.AddCommand(archiverCompressCmd)
archiverCmd.AddCommand(archiverDecompressCmd)
archiverCmd.AddCommand(newVersionCmd("arc", archiverVersion))
archiverDecompressCmd.Flags().BoolVar(&unarchiveAll, "decompress-all", false, "Decompress all tarballs in the archive")
archiverDecompressCmd.Flags().BoolVar(&unarchiveAll, "unarchive-all", false, "Unarchive all tarballs in the archive")
archiverDecompressCmd.MarkFlagsMutuallyExclusive("decompress-all", "unarchive-all")
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/tools/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package tools

import (
"fmt"

"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
Expand All @@ -31,3 +33,15 @@ var toolsCmd = &cobra.Command{
func Include(rootCmd *cobra.Command) {
rootCmd.AddCommand(toolsCmd)
}

// newVersionCmd is a generic version command for tools
func newVersionCmd(name, version string) *cobra.Command {
return &cobra.Command{
Use: "version",
Args: cobra.NoArgs,
Short: lang.CmdToolsVersionShort,
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(fmt.Sprintf("%s %s", name, version))
},
}
}
1 change: 1 addition & 0 deletions src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func init() {
registryCmd.AddCommand(zarfCraneInternalWrapper(craneCmd.NewCmdDelete, &craneOptions, lang.CmdToolsRegistryDeleteExample, 0))
registryCmd.AddCommand(zarfCraneInternalWrapper(craneCmd.NewCmdDigest, &craneOptions, lang.CmdToolsRegistryDigestExample, 0))
registryCmd.AddCommand(pruneCmd)
registryCmd.AddCommand(craneCmd.NewCmdVersion())

registryCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, lang.CmdToolsRegistryFlagVerbose)
registryCmd.PersistentFlags().BoolVar(&insecure, "insecure", false, lang.CmdToolsRegistryFlagInsecure)
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/tools/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"helm.sh/helm/v3/pkg/action"
)

// ldflags github.com/defenseunicorns/zarf/src/cmd/tools.helmVersion=x.x.x
var helmVersion string

func init() {
actionConfig := new(action.Configuration)

Expand All @@ -20,10 +23,11 @@ func init() {
if len(os.Args) > 2 {
helmArgs = os.Args[3:]
}
// The inclusion of Helm in this manner should be reconsidered once https://github.com/helm/helm/issues/12122 is resolved
// The inclusion of Helm in this manner should be changed once https://github.com/helm/helm/pull/12725 is merged
helmCmd, _ := helm.NewRootCmd(actionConfig, os.Stdout, helmArgs)
helmCmd.Short = lang.CmdToolsHelmShort
helmCmd.Long = lang.CmdToolsHelmLong
helmCmd.AddCommand(newVersionCmd("helm", helmVersion))

toolsCmd.AddCommand(helmCmd)
}
6 changes: 4 additions & 2 deletions src/cmd/tools/syft.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ package tools
import (
"github.com/anchore/clio"
syftCLI "github.com/anchore/syft/cmd/syft/cli"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
)

// ldflags github.com/defenseunicorns/zarf/src/cmd/tools.syftVersion=x.x.x
var syftVersion string

func init() {
syftCmd := syftCLI.Command(clio.Identification{
Name: "syft",
Version: config.CLIVersion,
Version: syftVersion,
})
syftCmd.Use = "sbom"
syftCmd.Short = lang.CmdToolsSbomShort
Expand Down
3 changes: 3 additions & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ $ zarf tools update-creds artifact --artifact-push-username={USERNAME} --artifac
CmdVersionShort = "Shows the version of the running Zarf binary"
CmdVersionLong = "Displays the version of the Zarf release that the current binary was built from."

// tools version
CmdToolsVersionShort = "Print the version"

// cmd viper setup
CmdViperErrLoadingConfigFile = "failed to load config file: %s"
CmdViperInfoUsingConfigFile = "Using config file %s"
Expand Down

0 comments on commit ce85228

Please sign in to comment.