Skip to content

Commit 7f2ab2e

Browse files
committed
build(docker): make binary versioning inside container consistent with goreleaser build
goreleaser currently strips the leading `v` off of the SemVer tag when passing to ldflags, while the container build does not remove it. Remove the leading `v`, if present, off of the version in container builds so that the version returned by `golangci-lint --version` is consistent regardless of whether the program is running standalone or in a container.
1 parent d131daf commit 7f2ab2e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

build/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ ARG DATE
77

88
COPY / /golangci
99
WORKDIR /golangci
10-
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
10+
RUN PROGRAM_VERSION=$VERSION && \
11+
PROGRAM_VERSION=${PROGRAM_VERSION#v} && \
12+
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$PROGRAM_VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
1113

1214
# stage 2
1315
FROM golang:1.21

build/alpine.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ WORKDIR /golangci
1212
# git and mercurial are needed most times for go get`, etc.
1313
# See https://github.com/docker-library/golang/issues/80
1414
RUN apk --no-cache add gcc musl-dev git mercurial
15-
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
15+
RUN PROGRAM_VERSION=$VERSION && \
16+
PROGRAM_VERSION=${PROGRAM_VERSION#v} && \
17+
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$PROGRAM_VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
1618

1719
# stage 2
1820
FROM golang:1.21-alpine

0 commit comments

Comments
 (0)