From b807e15a087461ad21f6e6b6ed2130160af13f4d Mon Sep 17 00:00:00 2001 From: Eddie Zaneski Date: Mon, 4 Mar 2024 12:32:09 -0700 Subject: [PATCH] feat: add missing vendored tool version commands (#2232) ## Description This PR adds missing version commands to the bundled tools. ## Related Issue Fixes #2142 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed Signed-off-by: Eddie Zaneski Co-authored-by: Wayne Starr --- .github/workflows/release.yml | 6 +++ .goreleaser.yaml | 5 +++ Makefile | 10 +++++ .../100-cli-commands/zarf_tools_archiver.md | 1 + .../zarf_tools_archiver_version.md | 31 +++++++++++++++ .../100-cli-commands/zarf_tools_helm.md | 1 + .../zarf_tools_helm_version.md | 39 +++++++++++++++++++ .../100-cli-commands/zarf_tools_registry.md | 1 + .../zarf_tools_registry_version.md | 34 ++++++++++++++++ src/cmd/tools/archiver.go | 5 +++ src/cmd/tools/common.go | 14 +++++++ src/cmd/tools/crane.go | 1 + src/cmd/tools/helm.go | 6 ++- src/cmd/tools/syft.go | 6 ++- src/config/lang/english.go | 3 ++ 15 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver_version.md create mode 100644 docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm_version.md create mode 100644 docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry_version.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 337d2f7e34..8e25be957b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -166,6 +166,12 @@ jobs: echo K8S_MODULES_MINOR_VER=$(echo "$K8S_MODULES_VER" | cut -d " " -f 2) >> $GITHUB_ENV echo K8S_MODULES_PATCH_VER=$(echo "$K8S_MODULES_VER" | cut -d " " -f 3) >> $GITHUB_ENV + echo K9S_VERSION=$(go list -f '{{.Version}}' -m github.com/derailed/k9s) >> $GITHUB_ENV + echo CRANE_VERSION=$(go list -f '{{.Version}}' -m github.com/google/go-containerregistry) >> $GITHUB_ENV + echo SYFT_VERSION=$(go list -f '{{.Version}}' -m github.com/anchore/syft) >> $GITHUB_ENV + echo ARCHIVER_VERSION=$(go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) >> $GITHUB_ENV + echo HELM_VERSION=$(go list -f '{{.Version}}' -m helm.sh/helm/v3) >> $GITHUB_ENV + # Create the GitHub release notes, upload artifact backups to S3, publish homebrew recipe - name: Run GoReleaser uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3010314a4a..afb41ad4d1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -23,6 +23,11 @@ builds: - -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMinor={{.Env.K8S_MODULES_MINOR_VER}} - -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor={{.Env.K8S_MODULES_MAJOR_VER}} - -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor={{.Env.K8S_MODULES_MINOR_VER}} + - -X github.com/derailed/k9s/cmd.version={{.Env.K9S_VERSION}} + - -X github.com/google/go-containerregistry/cmd/crane/cmd.Version={{.Env.CRANE_VERSION}} + - -X github.com/defenseunicorns/zarf/src/cmd/tools.syftVersion={{.Env.SYFT_VERSION}} + - -X github.com/defenseunicorns/zarf/src/cmd/tools.archiverVersion={{.Env.ARCHIVER_VERSION}} + - -X github.com/defenseunicorns/zarf/src/cmd/tools.helmVersion={{.Env.HELM_VERSION}} goarch: - amd64 - arm64 diff --git a/Makefile b/Makefile index 6a6b216a01..142669779a 100644 --- a/Makefile +++ b/Makefile @@ -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') diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver.md index 0aae1501be..1dd729b38a 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver.md @@ -27,3 +27,4 @@ Compresses/Decompresses generic archives, including Zarf packages * [zarf tools](zarf_tools.md) - Collection of additional tools to make airgap easier * [zarf tools archiver compress](zarf_tools_archiver_compress.md) - Compresses a collection of sources based off of the destination file extension. * [zarf tools archiver decompress](zarf_tools_archiver_decompress.md) - Decompresses an archive or Zarf package based off of the source file extension. +* [zarf tools archiver version](zarf_tools_archiver_version.md) - Print the version diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver_version.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver_version.md new file mode 100644 index 0000000000..6397622fc4 --- /dev/null +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_archiver_version.md @@ -0,0 +1,31 @@ +# zarf tools archiver version + + +Print the version + +``` +zarf tools archiver version [flags] +``` + +## Options + +``` + -h, --help help for version +``` + +## Options inherited from parent commands + +``` + -a, --architecture string Architecture for OCI images and Zarf packages + --insecure Allow access to insecure registries and disable other recommended security enforcements such as package checksum and signature validation. This flag should only be used if you have a specific reason and accept the reduced security posture. + -l, --log-level string Log level when running Zarf. Valid options are: warn, info, debug, trace (default "info") + --no-color Disable colors in output + --no-log-file Disable log file creation + --no-progress Disable fancy UI progress bars, spinners, logos, etc + --tmpdir string Specify the temporary directory to use for intermediate files + --zarf-cache string Specify the location of the Zarf cache directory (default "~/.zarf-cache") +``` + +## SEE ALSO + +* [zarf tools archiver](zarf_tools_archiver.md) - Compresses/Decompresses generic archives, including Zarf packages diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm.md index b8be9f7326..6c3ac76d13 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm.md @@ -34,3 +34,4 @@ Subset of the Helm CLI that includes the repo and dependency commands for managi * [zarf tools](zarf_tools.md) - Collection of additional tools to make airgap easier * [zarf tools helm dependency](zarf_tools_helm_dependency.md) - manage a chart's dependencies * [zarf tools helm repo](zarf_tools_helm_repo.md) - add, list, remove, update, and index chart repositories +* [zarf tools helm version](zarf_tools_helm_version.md) - Print the version diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm_version.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm_version.md new file mode 100644 index 0000000000..82942f2780 --- /dev/null +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm_version.md @@ -0,0 +1,39 @@ +# zarf tools helm version + + +Print the version + +``` +zarf tools helm version [flags] +``` + +## Options + +``` + -h, --help help for version +``` + +## Options inherited from parent commands + +``` + --burst-limit int client-side default throttling limit (default 100) + --debug enable verbose output + --kube-apiserver string the address and the port for the Kubernetes API server + --kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups. + --kube-as-user string username to impersonate for the operation + --kube-ca-file string the certificate authority file for the Kubernetes API server connection + --kube-context string name of the kubeconfig context to use + --kube-insecure-skip-tls-verify if true, the Kubernetes API server's certificate will not be checked for validity. This will make your HTTPS connections insecure + --kube-tls-server-name string server name to use for Kubernetes API server certificate validation. If it is not provided, the hostname used to contact the server is used + --kube-token string bearer token used for authentication + --kubeconfig string path to the kubeconfig file + -n, --namespace string namespace scope for this request + --qps float32 queries per second used when communicating with the Kubernetes API, not including bursting + --registry-config string path to the registry config file + --repository-cache string path to the file containing cached repository indexes + --repository-config string path to the file containing repository names and URLs +``` + +## SEE ALSO + +* [zarf tools helm](zarf_tools_helm.md) - Subset of the Helm CLI included with Zarf to help manage helm charts. diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry.md index 9233af1a26..7ee734ae10 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry.md @@ -25,3 +25,4 @@ Tools for working with container registries using go-containertools * [zarf tools registry prune](zarf_tools_registry_prune.md) - Prunes images from the registry that are not currently being used by any Zarf packages. * [zarf tools registry pull](zarf_tools_registry_pull.md) - Pull remote images by reference and store their contents locally * [zarf tools registry push](zarf_tools_registry_push.md) - Push local image contents to a remote registry +* [zarf tools registry version](zarf_tools_registry_version.md) - Print the version diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry_version.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry_version.md new file mode 100644 index 0000000000..6d6cf0df3f --- /dev/null +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_tools_registry_version.md @@ -0,0 +1,34 @@ +# zarf tools registry version + + +Print the version + +## Synopsis + +The version string is completely dependent on how the binary was built, so you should not depend on the version format. It may change without notice. + +This could be an arbitrary string, if specified via -ldflags. +This could also be the go module version, if built with go modules (often "(devel)"). + +``` +zarf tools registry version [flags] +``` + +## Options + +``` + -h, --help help for version +``` + +## Options inherited from parent commands + +``` + --allow-nondistributable-artifacts Allow pushing non-distributable (foreign) layers + --insecure Allow image references to be fetched without TLS + --platform string Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default "all") + -v, --verbose Enable debug logs +``` + +## SEE ALSO + +* [zarf tools registry](zarf_tools_registry.md) - Tools for working with container registries using go-containertools diff --git a/src/cmd/tools/archiver.go b/src/cmd/tools/archiver.go index b6110b7a18..9a1ee1c022 100644 --- a/src/cmd/tools/archiver.go +++ b/src/cmd/tools/archiver.go @@ -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{ @@ -85,6 +89,7 @@ func init() { archiverCmd.AddCommand(archiverCompressCmd) archiverCmd.AddCommand(archiverDecompressCmd) + archiverCmd.AddCommand(newVersionCmd("mholt/archiver", 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") diff --git a/src/cmd/tools/common.go b/src/cmd/tools/common.go index d0fa000e86..0844df9801 100644 --- a/src/cmd/tools/common.go +++ b/src/cmd/tools/common.go @@ -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" @@ -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, _ []string) { + cmd.Println(fmt.Sprintf("%s %s", name, version)) + }, + } +} diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index c0a521c153..b3ddd32e17 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -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) diff --git a/src/cmd/tools/helm.go b/src/cmd/tools/helm.go index 14c150acf5..dd2bf30d76 100644 --- a/src/cmd/tools/helm.go +++ b/src/cmd/tools/helm.go @@ -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) @@ -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) } diff --git a/src/cmd/tools/syft.go b/src/cmd/tools/syft.go index 68209c0553..1b466027a3 100644 --- a/src/cmd/tools/syft.go +++ b/src/cmd/tools/syft.go @@ -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 diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 14e3b19887..76487fb44e 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -593,6 +593,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"