Skip to content

Add version ldflags to Dockerfile build #20

@NP-compete

Description

@NP-compete

Summary

The Dockerfile doesn't use version ldflags during build, unlike the Makefile.

Current State

```dockerfile

Dockerfile:20

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/bin/gomcp ./cmd/server
```

```makefile

Makefile:32-36

build-prod:
@CGO_ENABLED=0 go build \
$(LDFLAGS) \
-trimpath \
-o $(BINARY_PATH) \
./cmd/server
```

Problem

Docker builds don't include version information, making it hard to identify which version is running in a container.

Expected Outcome

```dockerfile

Build stage

FROM golang:1.24-alpine AS builder

ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG BUILD_TIME=unknown

... existing setup ...

Build with version info

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X github.com/NP-compete/gomcp/internal/version.Version=${VERSION} \
-X github.com/NP-compete/gomcp/internal/version.GitCommit=${GIT_COMMIT} \
-X github.com/NP-compete/gomcp/internal/version.BuildTime=${BUILD_TIME}" \
-trimpath \
-o /app/bin/gomcp ./cmd/server
```

Build command

```bash
docker build \
--build-arg VERSION=$(cat VERSION) \
--build-arg GIT_COMMIT=$(git rev-parse --short HEAD) \
--build-arg BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S') \
-t gomcp-server .
```

Update Makefile

```makefile
docker-build:
@docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
-t $(DOCKER_IMAGE):$(DOCKER_TAG) .
```

Acceptance Criteria

  • Dockerfile accepts VERSION, GIT_COMMIT, BUILD_TIME build args
  • Binary in container reports correct version
  • Makefile docker-build passes version info
  • CI workflow passes version info to Docker build
  • `gomcp --version` in container shows build info

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions