From b1307df1e44ccd108fac29ec8ddb4e54f441f30d Mon Sep 17 00:00:00 2001 From: Ori Bendet Date: Mon, 2 Mar 2026 11:52:40 -0500 Subject: [PATCH] fix(build): inject version number in Makefile and Dockerfile builds Local and Docker builds were missing the -X linker flag that injects the version at compile time, causing `2ms --version` to always report 0.0.0 on Linux and in containers. - Makefile build-local: use `git describe --tags` to derive the version from the current git tag automatically, falling back to "dev" - Dockerfile: add a VERSION build arg (default "dev") and pass it via -X so `docker build --build-arg VERSION=x.y.z .` produces a correctly versioned image Fixes #360 Co-Authored-By: Claude Sonnet 4.6 --- Dockerfile | 3 ++- Makefile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0b6c483c..c1c6996d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,8 @@ RUN go mod download # COPY the source code as the last step COPY . . -RUN GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w" -a -o /app/2ms . +ARG VERSION=dev +RUN GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w -X github.com/checkmarx/2ms/v5/cmd.Version=${VERSION}" -a -o /app/2ms . # Runtime image FROM checkmarx/git:2.53.0-r0-dadf19ec31d471@sha256:dadf19ec31d4711eeace2763e89511693b36ba0ea5c9e12a763978b4b29ddba0 diff --git a/Makefile b/Makefile index f36cfd09..cdfd9c08 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ build: docker build -t $(image_name) . build-local: - GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w" -a -o ./2ms . + GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags="-s -w -X github.com/checkmarx/2ms/v5/cmd.Version=$(shell git describe --tags --always 2>/dev/null || echo dev)" -a -o ./2ms . generate: check-mockgen-version go generate ./...