Skip to content

Commit

Permalink
feat: inject version from tags
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Gagnaux <[email protected]>
  • Loading branch information
tricktron committed Nov 28, 2023
1 parent d6688c1 commit 7a730e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MANINSTALLDIR=${PREFIX}/share/man
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")
VERSION := $(shell git describe --tags --always | cut -c 2-)
DOCKER_IMAGE := manifest-tool-dev$(if $(GIT_BRANCH),:$(GIT_BRANCH))
# set env like gobuildtag?
DOCKER_RUN := docker run --rm -i #$(DOCKER_ENVS)
Expand All @@ -22,17 +23,19 @@ DOCKER_RUN_DOCKER := $(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/man
all: binary

build:
$(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.17 /bin/bash -c "\
cd v2 && go build -ldflags \"-X main.gitCommit=${COMMIT}\" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"
$(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.20 /bin/bash -c "\
cd v2 && go build -ldflags \"-X main.gitCommit=${COMMIT} main.version=${VERSION}\" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"

# Target to build a dynamically linked binary
binary: v2/pkg/util/oslist.go
cd v2 && go build -ldflags "-X main.gitCommit=${COMMIT}" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
cd v2 && go build \
-ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" \
-o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool

# Target to build a statically linked binary
static: v2/pkg/util/oslist.go
cd v2 && GO_EXTLINK_ENABLED=0 CGO_ENABLED=0 go build \
-ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT}" \
-ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" \
-tags netgo -installsuffix netgo \
-o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool

Expand Down
2 changes: 1 addition & 1 deletion v2/cmd/manifest-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

// filled in at compile time
var gitCommit = ""
var version = ""

const (
version = "2.1.2"
usage = "registry client to inspect and push multi-platform OCI & Docker v2 images"
)

Expand Down

0 comments on commit 7a730e3

Please sign in to comment.