mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
version: add commit id to binary during build
This commit is contained in:
parent
487df473c5
commit
4d73d8ff47
3 changed files with 10 additions and 3 deletions
6
Makefile
6
Makefile
|
@ -1,5 +1,7 @@
|
||||||
export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
TOP_LEVEL=$(shell git rev-parse --show-toplevel)
|
TOP_LEVEL=$(shell git rev-parse --show-toplevel)
|
||||||
|
COMMIT_HASH=$(shell git describe --always --tags --long)
|
||||||
|
COMMIT=$(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH))
|
||||||
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
|
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
|
||||||
PATH := bin:$(PATH)
|
PATH := bin:$(PATH)
|
||||||
|
|
||||||
|
@ -8,11 +10,11 @@ all: doc binary debug test check
|
||||||
|
|
||||||
.PHONY: binary
|
.PHONY: binary
|
||||||
binary: doc
|
binary: doc
|
||||||
go build -v -o bin/zot -tags=jsoniter ./cmd/zot
|
go build -v -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT}" -o bin/zot -tags=jsoniter ./cmd/zot
|
||||||
|
|
||||||
.PHONY: debug
|
.PHONY: debug
|
||||||
debug: doc
|
debug: doc
|
||||||
go build -v -gcflags all='-N -l' -o bin/zot-debug -tags=jsoniter ./cmd/zot
|
go build -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api.Commit=${COMMIT}" -o bin/zot-debug -tags=jsoniter ./cmd/zot
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
|
|
|
@ -4,6 +4,9 @@ import (
|
||||||
dspec "github.com/opencontainers/distribution-spec"
|
dspec "github.com/opencontainers/distribution-spec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//nolint (gochecknoglobals)
|
||||||
|
var Commit string
|
||||||
|
|
||||||
type StorageConfig struct {
|
type StorageConfig struct {
|
||||||
RootDirectory string
|
RootDirectory string
|
||||||
}
|
}
|
||||||
|
@ -39,6 +42,7 @@ type LogConfig struct {
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string
|
Version string
|
||||||
|
Commit string
|
||||||
Storage StorageConfig
|
Storage StorageConfig
|
||||||
HTTP HTTPConfig
|
HTTP HTTPConfig
|
||||||
Log LogConfig `mapstructure:",omitempty"`
|
Log LogConfig `mapstructure:",omitempty"`
|
||||||
|
@ -47,6 +51,7 @@ type Config struct {
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Version: dspec.Version,
|
Version: dspec.Version,
|
||||||
|
Commit: Commit,
|
||||||
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
||||||
Log: LogConfig{Level: "debug"},
|
Log: LogConfig{Level: "debug"},
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ func NewRootCmd() *cobra.Command {
|
||||||
Long: "`zot`",
|
Long: "`zot`",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if showVersion {
|
if showVersion {
|
||||||
log.Info().Str("version", dspec.Version).Msg("distribution-spec")
|
log.Info().Str("distribution-spec", dspec.Version).Str("commit", api.Commit).Msg("version")
|
||||||
}
|
}
|
||||||
_ = cmd.Usage()
|
_ = cmd.Usage()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue