Skip to content

Commit e5bde4f

Browse files
committed
BUILD/MEDIUM: enable VCS version stamping in compiled binary
Modify the Dockerfile and GitHub Actions workflow to ensure Go embeds accurate version control information into the compiled binary. This allows debug.ReadBuildInfo to read the correct version and commit hash during runtime.
1 parent 8347bec commit e5bde4f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

.github/workflows/build_on_tag.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424

2525
steps:
2626
- uses: actions/checkout@v4
27+
with:
28+
# full history + tags so go build stamps the real version
29+
fetch-depth: 0
2730

2831
- name: Build image
2932
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
FROM golang:alpine AS builder
2+
# git is required for VCS version stamping (debug.ReadBuildInfo)
3+
RUN apk --no-cache add git
24
RUN mkdir /build
35
ADD . /build/
46
WORKDIR /build
5-
RUN go build -o check
7+
RUN go build -buildvcs=true -o check
68

79
FROM alpine:latest
810
RUN apk --no-cache add aspell aspell-en

0 commit comments

Comments
 (0)