Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing vendored tool version commands #2232

Merged
merged 2 commits into from
Mar 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Makefile
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
Expand Up @@ -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
@@ -0,0 +1,31 @@
# zarf tools archiver version
<!-- Auto-generated by hack/gen-cli-docs.sh -->

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
1 change: 1 addition & 0 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm.md
Expand Up @@ -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
39 changes: 39 additions & 0 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_tools_helm_version.md
@@ -0,0 +1,39 @@
# zarf tools helm version
<!-- Auto-generated by hack/gen-cli-docs.sh -->

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.
Expand Up @@ -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
@@ -0,0 +1,34 @@
# zarf tools registry version
<!-- Auto-generated by hack/gen-cli-docs.sh -->

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
5 changes: 5 additions & 0 deletions src/cmd/tools/archiver.go
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("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")
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/tools/common.go
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, _ []string) {
cmd.Println(fmt.Sprintf("%s %s", name, version))
},
}
}
1 change: 1 addition & 0 deletions src/cmd/tools/crane.go
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
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
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
Expand Up @@ -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"
Expand Down