From f3b1913fbd2fbd8cd86c89fefd25c9dbdcf9e14f Mon Sep 17 00:00:00 2001 From: Catalin Hofnar Date: Tue, 11 Oct 2022 19:01:59 +0300 Subject: [PATCH] build: add commit hash to Config at build for proper discovery readme (#854) * build: add commit hash to Config at build for proper discovery readme link * fix: use tag instead of commit hash, add to release build Signed-off-by: Catalin Hofnar --- .github/workflows/ci-cd.yml | 2 ++ Makefile | 7 ++++--- pkg/api/config/config.go | 3 +++ pkg/extensions/extension_search.go | 4 ++-- stacker.yaml | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 988de6c8..2de57b57 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -153,6 +153,7 @@ jobs: with: file: 'stacker.yaml' build-args: | + RELEASE_TAG=${{ github.event.release.tag_name }} COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} OS=${{ matrix.os }} ARCH=${{ matrix.arch }} @@ -198,6 +199,7 @@ jobs: with: file: 'stacker.yaml' build-args: | + RELEASE_TAG=${{ github.event.release.tag_name }} COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} OS=${{ matrix.os }} ARCH=${{ matrix.arch }} diff --git a/Makefile b/Makefile index 655061f9..0abaa903 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ export GO111MODULE=on TOP_LEVEL=$(shell git rev-parse --show-toplevel) COMMIT_HASH=$(shell git describe --always --tags --long) +RELEASE_TAG=$(shell git describe --tags --abbrev=0) GO_VERSION=$(shell go version | awk '{print $$3}') 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) @@ -47,15 +48,15 @@ build-metadata: .PHONY: binary-minimal binary-minimal: EXTENSIONS=minimal # tag doesn't exist, but we need it to overwrite default value and indicate that we have no extension in build-metadata binary-minimal: modcheck build-metadata - env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-minimal -buildmode=pie -tags containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=minimal -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-minimal -buildmode=pie -tags containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.io/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=minimal -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot .PHONY: binary binary: modcheck create-name build-metadata - env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH) -buildmode=pie -tags $(EXTENSIONS),containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH) -buildmode=pie -tags $(EXTENSIONS),containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.io/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot .PHONY: binary-debug binary-debug: modcheck swagger create-name build-metadata - env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-debug -buildmode=pie -tags $(EXTENSIONS),debug,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-debug -buildmode=pie -tags $(EXTENSIONS),debug,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X zotregistry.io/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot .PHONY: cli cli: modcheck create-name build-metadata diff --git a/pkg/api/config/config.go b/pkg/api/config/config.go index 8a0ff050..dd7dbe2b 100644 --- a/pkg/api/config/config.go +++ b/pkg/api/config/config.go @@ -14,6 +14,7 @@ import ( var ( Commit string //nolint: gochecknoglobals + ReleaseTag string //nolint: gochecknoglobals BinaryType string //nolint: gochecknoglobals GoVersion string //nolint: gochecknoglobals ) @@ -125,6 +126,7 @@ type Config struct { DistSpecVersion string `json:"distSpecVersion" mapstructure:"distSpecVersion"` GoVersion string Commit string + ReleaseTag string BinaryType string AccessControl *AccessControlConfig Storage GlobalStorageConfig @@ -138,6 +140,7 @@ func New() *Config { DistSpecVersion: distspec.Version, GoVersion: GoVersion, Commit: Commit, + ReleaseTag: ReleaseTag, BinaryType: BinaryType, Storage: GlobalStorageConfig{GC: true, GCDelay: storage.DefaultGCDelay, Dedupe: true}, HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080", Auth: &AuthConfig{FailDelay: 0}}, diff --git a/pkg/extensions/extension_search.go b/pkg/extensions/extension_search.go index e1cf5a6e..331ca117 100644 --- a/pkg/extensions/extension_search.go +++ b/pkg/extensions/extension_search.go @@ -103,8 +103,8 @@ func GetExtensions(config *config.Config) distext.ExtensionList { if config.Extensions != nil && config.Extensions.Search != nil { endpoints := []string{constants.ExtSearchPrefix} searchExt := getExtension("_zot", - "https://github.com/project-zot/zot/tree/main/pkg/extensions/_zot.md", - "zot registry extension", + "https://github.com/project-zot/zot/blob/"+config.ReleaseTag+"/pkg/extensions/_zot.md", + "zot registry extensions", endpoints) extensions = append(extensions, searchExt) diff --git a/stacker.yaml b/stacker.yaml index d0e71b10..3a229e24 100644 --- a/stacker.yaml +++ b/stacker.yaml @@ -13,7 +13,7 @@ build: cd /go/src/github.com/project-zot git clone /zotcopy zot cd /go/src/github.com/project-zot/zot - make COMMIT=${{COMMIT}} OS=${{OS}} ARCH=${{ARCH}} clean binary${{EXT:}} + make COMMIT=${{COMMIT}} OS=${{OS}} ARCH=${{ARCH}} RELEASE_TAG=&{{RELEASE_TAG}} clean binary${{EXT:}} cat > config.json << EOF { "storage":{