diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2b8d43b8..e9ffb7bc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,3 +29,4 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ebea693a..7e6460ee 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -3,6 +3,10 @@ before: hooks: - go mod tidy - go mod download + +env: + - vpkg=github.com/rancherfederal/hauler/pkg/version + builds: - main: cmd/hauler/main.go goos: @@ -12,6 +16,8 @@ builds: goarch: - amd64 - arm64 + ldflags: + - -s -w -X {{ .Env.vpkg }}.GitVersion={{ .Version }} -X {{ .Env.vpkg }}.commit={{ .ShortCommit }} -X {{ .Env.vpkg }}.buildDate={{ .Date }} env: - CGO_ENABLED=0 diff --git a/cmd/hauler/cli/cli.go b/cmd/hauler/cli/cli.go index cd750805..b1591b08 100644 --- a/cmd/hauler/cli/cli.go +++ b/cmd/hauler/cli/cli.go @@ -44,6 +44,7 @@ func New() *cobra.Command { // Add subcommands addDownload(cmd) addStore(cmd) + addVersion(cmd) return cmd } diff --git a/cmd/hauler/cli/download/download.go b/cmd/hauler/cli/download/download.go index ff383880..2bfe4342 100644 --- a/cmd/hauler/cli/download/download.go +++ b/cmd/hauler/cli/download/download.go @@ -81,7 +81,7 @@ func Cmd(ctx context.Context, o *Opts, reference string) error { lgr.Infof("downloaded [%s] to [%s]", ref.Name(), outputFile) - case types.FileMediaType: + case types.FileConfigMediaType: lgr.Infof("identified [file] (%s) content", manifest.Config.MediaType) fs := content.NewFileStore(o.DestinationDir) diff --git a/cmd/hauler/cli/version.go b/cmd/hauler/cli/version.go new file mode 100644 index 00000000..7e027959 --- /dev/null +++ b/cmd/hauler/cli/version.go @@ -0,0 +1,37 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/rancherfederal/hauler/pkg/version" +) + +func addVersion(parent *cobra.Command) { + var json bool + + cmd := &cobra.Command{ + Use: "version", + Short: "Print current hauler version", + Long: "Print current hauler version", + Aliases: []string{"v"}, + RunE: func(cmd *cobra.Command, args []string) error { + v := version.GetVersionInfo() + response := v.String() + if json { + data, err := v.JSONString() + if err != nil { + return err + } + response = data + } + fmt.Print(response) + return nil + }, + } + + cmd.Flags().BoolVar(&json, "json", false, "toggle output in JSON") + + parent.AddCommand(cmd) +} diff --git a/pkg/artifact/types/types.go b/pkg/artifact/types/types.go index 10d5508d..c1e50fa2 100644 --- a/pkg/artifact/types/types.go +++ b/pkg/artifact/types/types.go @@ -3,14 +3,10 @@ package types const ( OCIManifestSchema1 = "application/vnd.oci.image.manifest.v1+json" DockerManifestSchema2 = "application/vnd.docker.distribution.manifest.v2+json" - DockerConfigJSON = "application/vnd.docker.container.image.v1+json" - UnknownManifest = "application/vnd.hauler.cattle.io.unknown.v1+json" - UnknownLayer = "application/vnd.content.hauler.unknown.layer" - FileLayerMediaType = "application/vnd.content.hauler.file.layer.v1" - FileMediaType = "application/vnd.content.hauler.file.config.v1+json" + DockerConfigJSON = "application/vnd.docker.container.image.v1+json" - // ConfigMediaType is the reserved media type for the Helm chart manifest config + // ChartConfigMediaType is the reserved media type for the Helm chart manifest config ChartConfigMediaType = "application/vnd.cncf.helm.config.v1+json" // ChartLayerMediaType is the reserved media type for Helm chart package content @@ -19,6 +15,21 @@ const ( // ProvLayerMediaType is the reserved media type for Helm chart provenance files ProvLayerMediaType = "application/vnd.cncf.helm.chart.provenance.v1.prov" + // FileLayerMediaType is the reserved media type for File content layers + FileLayerMediaType = "application/vnd.content.hauler.file.layer.v1" + + // FileConfigMediaType is the reserved media type for File config + FileConfigMediaType = "application/vnd.content.hauler.file.config.v1+json" + + // WasmArtifactLayerMediaType is the reserved media type for WASM artifact layers + WasmArtifactLayerMediaType = "application/vnd.wasm.content.layer.v1+wasm" + + // WasmConfigMediaType is the reserved media type for WASM configs + WasmConfigMediaType = "application/vnd.wasm.config.v1+json" + + UnknownManifest = "application/vnd.hauler.cattle.io.unknown.v1+json" + UnknownLayer = "application/vnd.content.hauler.unknown.layer" + OCIVendorPrefix = "vnd.oci" DockerVendorPrefix = "vnd.docker" HaulerVendorPrefix = "vnd.hauler" diff --git a/pkg/content/file/config.go b/pkg/content/file/config.go index 26863da2..5511ea94 100644 --- a/pkg/content/file/config.go +++ b/pkg/content/file/config.go @@ -30,7 +30,7 @@ func (c config) Descriptor() (gv1.Descriptor, error) { } return gv1.Descriptor{ - MediaType: types.FileMediaType, + MediaType: types.FileConfigMediaType, Size: c.size, Digest: c.hash, URLs: c.URLs, @@ -47,7 +47,7 @@ func (c config) Digest() (gv1.Hash, error) { } func (c config) MediaType() (gtypes.MediaType, error) { - return types.FileMediaType, nil + return types.FileConfigMediaType, nil } func (c config) Size() (int64, error) { diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 00000000..656aa367 --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,61 @@ +package version + +import ( + "encoding/json" + "fmt" + "path" + "runtime" + "strings" + "text/tabwriter" +) + +var ( + GitVersion = "devel" + commit = "unknown" + buildDate = "unknown" +) + +type Info struct { + GitVersion string + GitCommit string + BuildDate string + + GoVersion string + Compiler string + Platform string +} + +func GetVersionInfo() Info { + return Info{ + GitVersion: GitVersion, + GitCommit: commit, + BuildDate: buildDate, + + GoVersion: runtime.Version(), + Compiler: runtime.Compiler, + Platform: path.Join(runtime.GOOS, runtime.GOARCH), + } +} + +func (i Info) String() string { + b := strings.Builder{} + w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0) + + fmt.Fprintf(w, "GitVersion:\t%s\n", i.GitVersion) + fmt.Fprintf(w, "GitCommit:\t%s\n", i.GitCommit) + fmt.Fprintf(w, "BuildDate:\t%s\n", i.BuildDate) + fmt.Fprintf(w, "GoVersion:\t%s\n", i.GoVersion) + fmt.Fprintf(w, "Compiler:\t%s\n", i.Compiler) + fmt.Fprintf(w, "Platform:\t%s\n", i.Platform) + + w.Flush() + return b.String() +} + +func (i Info) JSONString() (string, error) { + b, err := json.MarshalIndent(i, "", " ") + if err != nil { + return "", err + } + return string(b), nil +} diff --git a/scripts/save-docker-image-tar.sh b/scripts/save-docker-image-tar.sh deleted file mode 100755 index a0071a83..00000000 --- a/scripts/save-docker-image-tar.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -IMAGE_NAME="$1" -SAVE_DIR="$2" - -if [ -z "${IMAGE_NAME}" ]; then - echo "[Usage] ./save-docker-image.sh " - exit 1 -fi - -if [ -z "$2" ]; then - SAVE_DIR="." - -fi - -echo "Creating ${IMAGE_NAME} backup..." -#docker save ${IMAGE_NAME} | gzip --stdout > ${SAVE_DIR}/${IMAGE_NAME}.tgz -docker save ${IMAGE_NAME} > ${IMAGE_NAME}.tar diff --git a/scripts/save-docker-image.sh b/scripts/save-docker-image.sh deleted file mode 100755 index c75a7f83..00000000 --- a/scripts/save-docker-image.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -IMAGE_NAME="$1" -SAVE_DIR="$2" - -if [ -z "${IMAGE_NAME}" ]; then - echo "[Usage] ./save-docker-image.sh " - exit 1 -fi - -if [ -z "$2" ]; then - SAVE_DIR="." - -fi - -echo "Creating ${IMAGE_NAME} backup..." -docker save ${IMAGE_NAME} | gzip --stdout > ${SAVE_DIR}/${IMAGE_NAME}.tgz diff --git a/scripts/save-k3s-artifacts.sh b/scripts/save-k3s-artifacts.sh deleted file mode 100755 index 41385c55..00000000 --- a/scripts/save-k3s-artifacts.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -K3S_RELEASE="v1.18.8-rc1%2Bk3s1" - -SAVE_DIR="$1" - -if [ -z "$1" ]; then - SAVE_DIR="." -fi - -# k3s - arm64 -wget -P ${SAVE_DIR} https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s-arm64 - -# k3s - amd64 -wget -P ${SAVE_DIR} https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s - -# images - amd64 -wget -P ${SAVE_DIR} https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s-airgap-images-amd64.tar - -# images - arm64 -wget -P ${SAVE_DIR} https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s-airgap-images-arm64.tar - -# images.txt -wget -P ${SAVE_DIR} https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s-images.txt -