diff --git a/Dockerfile b/Dockerfile index 045f83219..b74e04c71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,9 +36,11 @@ FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS lint-base FROM base AS lint ENV CGO_ENABLED=0 COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint +ARG GIT_TAG RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/root/.cache/golangci-lint \ + GIT_TAG=${GIT_TAG} \ make -f builder.Makefile lint FROM base AS make-cli @@ -46,18 +48,22 @@ ENV CGO_ENABLED=0 ARG TARGETOS ARG TARGETARCH ARG BUILD_TAGS +ARG GIT_TAG RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ GOOS=${TARGETOS} \ GOARCH=${TARGETARCH} \ BUILD_TAGS=${BUILD_TAGS} \ + GIT_TAG=${GIT_TAG} \ make BINARY=/out/docker -f builder.Makefile cli FROM base AS make-cross ARG BUILD_TAGS +ARG GIT_TAG RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ BUILD_TAGS=${BUILD_TAGS} \ + GIT_TAG=${GIT_TAG} \ make BINARY=/out/docker -f builder.Makefile cross FROM scratch AS protos @@ -70,9 +76,11 @@ FROM scratch AS cross COPY --from=make-cross /out/* . FROM base as test -ARG BUILD_TAGS ENV CGO_ENABLED=0 +ARG BUILD_TAGS +ARG GIT_TAG RUN --mount=target=. \ --mount=type=cache,target=/root/.cache/go-build \ BUILD_TAGS=${BUILD_TAGS} \ + GIT_TAG=${GIT_TAG} \ make -f builder.Makefile test diff --git a/Makefile b/Makefile index 451eeeee9..a5a3d6023 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ ifeq ($(UNAME_S),Darwin) MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker endif +GIT_TAG?=$(shell git describe --tags --match "v[0-9]*") + all: cli protos: ## Generate go code from .proto files @@ -32,6 +34,7 @@ cli: ## Compile the cli @docker build . --target cli \ --platform local \ --build-arg BUILD_TAGS=example,local \ + --build-arg GIT_TAG=$(GIT_TAG) \ --output ./bin e2e-local: ## Run End to end local tests @@ -46,18 +49,22 @@ e2e-aci: ## Run End to end ACI tests (requires azure login) cross: ## Compile the CLI for linux, darwin and windows @docker build . --target cross \ --build-arg BUILD_TAGS \ + --build-arg GIT_TAG=$(GIT_TAG) \ --output ./bin \ test: ## Run unit tests @docker build . \ --build-arg BUILD_TAGS=example,local \ + --build-arg GIT_TAG=$(GIT_TAG) \ --target test cache-clear: ## Clear the builder cache @docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h lint: ## run linter(s) - @docker build . --target lint + @docker build . \ + --build-arg GIT_TAG=$(GIT_TAG) \ + --target lint serve: cli ## start server @./bin/docker serve --address unix:///tmp/backend.sock diff --git a/builder.Makefile b/builder.Makefile index c76668106..b5e131484 100644 --- a/builder.Makefile +++ b/builder.Makefile @@ -23,7 +23,8 @@ ifeq ($(GOOS),windows) endif STATIC_FLAGS=CGO_ENABLED=0 -GIT_TAG=$(shell git describe --tags --match "v[0-9]*") + +GIT_TAG?=$(shell git describe --tags --match "v[0-9]*") LDFLAGS="-s -w -X main.version=${GIT_TAG}" GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)