From cf25c6f3c859dbbfe6d9b14155a9d338336c8743 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 12 Feb 2021 16:52:02 -0800 Subject: [PATCH] ci/cd:inculde binary type in version information --- Makefile | 6 +++--- pkg/api/config.go | 19 ++++++++++++------- pkg/cli/root.go | 3 ++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a05ff9c7..8599cc9f 100644 --- a/Makefile +++ b/Makefile @@ -12,15 +12,15 @@ all: doc binary binary-minimal debug test check .PHONY: binary-minimal binary-minimal: doc - go build -tags minimal -v -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT}" -o bin/zot-minimal ./cmd/zot + go build -tags minimal -v -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=minimal" -o bin/zot-minimal ./cmd/zot .PHONY: binary binary: doc - go build -tags extended -v -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT}" -o bin/zot ./cmd/zot + go build -tags extended -v -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=extended" -o bin/zot ./cmd/zot .PHONY: debug debug: doc - go build -tags extended -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT}" -o bin/zot-debug ./cmd/zot + go build -tags extended -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api.BinaryType=extended" -o bin/zot-debug ./cmd/zot .PHONY: test test: diff --git a/pkg/api/config.go b/pkg/api/config.go index e6ab1926..98403919 100644 --- a/pkg/api/config.go +++ b/pkg/api/config.go @@ -8,8 +8,11 @@ import ( dspec "github.com/opencontainers/distribution-spec" ) -// Commit ... -var Commit string //nolint: gochecknoglobals +// Global vars... +var ( + Commit string // nolint: gochecknoglobals + BinaryType string // nolint: gochecknoglobals +) type StorageConfig struct { RootDirectory string @@ -72,6 +75,7 @@ type LogConfig struct { type Config struct { Version string Commit string + BinaryType string Storage StorageConfig HTTP HTTPConfig Log *LogConfig @@ -80,11 +84,12 @@ type Config struct { func NewConfig() *Config { return &Config{ - Version: dspec.Version, - Commit: Commit, - Storage: StorageConfig{GC: true, Dedupe: true}, - HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"}, - Log: &LogConfig{Level: "debug"}, + Version: dspec.Version, + Commit: Commit, + BinaryType: BinaryType, + Storage: StorageConfig{GC: true, Dedupe: true}, + HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"}, + Log: &LogConfig{Level: "debug"}, } } diff --git a/pkg/cli/root.go b/pkg/cli/root.go index 85758d21..628c9995 100644 --- a/pkg/cli/root.go +++ b/pkg/cli/root.go @@ -88,7 +88,8 @@ func NewRootCmd() *cobra.Command { Long: "`zot`", Run: func(cmd *cobra.Command, args []string) { if showVersion { - log.Info().Str("distribution-spec", dspec.Version).Str("commit", api.Commit).Msg("version") + log.Info().Str("distribution-spec", dspec.Version).Str("commit", api.Commit). + Str("binary-type", api.BinaryType).Msg("version") } _ = cmd.Usage() },