mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
refactor(build): move build metadata to pkg/buildinfo (#4045)
Keep CLI binaries from importing pkg/api/config just for version strings by centralizing Commit/ReleaseTag/BinaryType/GoVersion in a tiny buildinfo package. Update ldflags targets and callers accordingly. Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
distspec "github.com/opencontainers/distribution-spec/specs-go"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"zotregistry.dev/zot/v2/pkg/api/config"
|
||||
"zotregistry.dev/zot/v2/pkg/buildinfo"
|
||||
"zotregistry.dev/zot/v2/pkg/log"
|
||||
)
|
||||
|
||||
@@ -21,8 +21,8 @@ func NewCliRootCmd() *cobra.Command {
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if showVersion {
|
||||
logger := log.NewLogger("info", "")
|
||||
logger.Info().Str("distribution-spec", distspec.Version).Str("commit", config.Commit).
|
||||
Str("binary-type", config.BinaryType).Str("go version", config.GoVersion).Msg("version")
|
||||
logger.Info().Str("distribution-spec", distspec.Version).Str("commit", buildinfo.Commit).
|
||||
Str("binary-type", buildinfo.BinaryType).Str("go version", buildinfo.GoVersion).Msg("version")
|
||||
} else {
|
||||
_ = cmd.Usage()
|
||||
cmd.SilenceErrors = false
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"zotregistry.dev/zot/v2/pkg/api"
|
||||
"zotregistry.dev/zot/v2/pkg/api/config"
|
||||
"zotregistry.dev/zot/v2/pkg/api/constants"
|
||||
"zotregistry.dev/zot/v2/pkg/buildinfo"
|
||||
extconf "zotregistry.dev/zot/v2/pkg/extensions/config"
|
||||
test "zotregistry.dev/zot/v2/pkg/test/common"
|
||||
)
|
||||
@@ -54,8 +55,8 @@ func TestServerStatusCommand(t *testing.T) {
|
||||
space := regexp.MustCompile(`\s+`)
|
||||
str := space.ReplaceAllString(buff.String(), " ")
|
||||
actual := strings.TrimSpace(str)
|
||||
So(actual, ShouldContainSubstring, config.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, config.BinaryType)
|
||||
So(actual, ShouldContainSubstring, buildinfo.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, buildinfo.BinaryType)
|
||||
|
||||
// JSON
|
||||
args = []string{"status", "--config", "status-test", "--format", "json"}
|
||||
@@ -69,8 +70,8 @@ func TestServerStatusCommand(t *testing.T) {
|
||||
space = regexp.MustCompile(`\s+`)
|
||||
str = space.ReplaceAllString(buff.String(), " ")
|
||||
actual = strings.TrimSpace(str)
|
||||
So(actual, ShouldContainSubstring, config.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, config.BinaryType)
|
||||
So(actual, ShouldContainSubstring, buildinfo.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, buildinfo.BinaryType)
|
||||
|
||||
// YAML
|
||||
args = []string{"status", "--config", "status-test", "--format", "yaml"}
|
||||
@@ -84,8 +85,8 @@ func TestServerStatusCommand(t *testing.T) {
|
||||
space = regexp.MustCompile(`\s+`)
|
||||
str = space.ReplaceAllString(buff.String(), " ")
|
||||
actual = strings.TrimSpace(str)
|
||||
So(actual, ShouldContainSubstring, config.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, config.BinaryType)
|
||||
So(actual, ShouldContainSubstring, buildinfo.ReleaseTag)
|
||||
So(actual, ShouldContainSubstring, buildinfo.BinaryType)
|
||||
|
||||
// bad type
|
||||
args = []string{"status", "--config", "status-test", "--format", "badType"}
|
||||
|
||||
Reference in New Issue
Block a user