Skip to content

Commit

Permalink
build(docker): make binary versioning inside container consistent wit…
Browse files Browse the repository at this point in the history
…h 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.
  • Loading branch information
alebcay committed Dec 21, 2023
1 parent d131daf commit 7f2ab2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ ARG DATE

COPY / /golangci
WORKDIR /golangci
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
RUN PROGRAM_VERSION=$VERSION && \
PROGRAM_VERSION=${PROGRAM_VERSION#v} && \
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

# stage 2
FROM golang:1.21
Expand Down
4 changes: 3 additions & 1 deletion build/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ WORKDIR /golangci
# git and mercurial are needed most times for go get`, etc.
# See https://github.com/docker-library/golang/issues/80
RUN apk --no-cache add gcc musl-dev git mercurial
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
RUN PROGRAM_VERSION=$VERSION && \
PROGRAM_VERSION=${PROGRAM_VERSION#v} && \
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

# stage 2
FROM golang:1.21-alpine
Expand Down

0 comments on commit 7f2ab2e

Please sign in to comment.