Skip to content

Commit af681a2

Browse files
committed
build(docker): Fix version details in docker image
As part of golangci#1383, multi-arch docker build was supported. However, ldflags for version details was missing. This commit is to add -ldflags as part of Docker build. Fixes golangci#1468 Signed-off-by: Tam Mach <[email protected]>
1 parent f414375 commit af681a2

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.github/workflows/tag.yml

+12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ jobs:
3131
run: |
3232
TAG=${GITHUB_REF#refs/tags/}
3333
MAJOR=${TAG%.*}
34+
SHORT_COMMIT=${GITHUB_SHA::8}
35+
DATE=$(date '+%Y-%m-%dT%H:%M:%SZ')
3436
echo ::set-output name=tag_name::${TAG}
3537
echo ::set-output name=major_tag::${MAJOR}
38+
echo ::set-output name=short_commit::${SHORT_COMMIT}
39+
echo ::set-output name=date::${DATE}
3640
- name: Set up QEMU
3741
uses: docker/setup-qemu-action@v1
3842
- name: Set up Docker Buildx
@@ -45,6 +49,10 @@ jobs:
4549
file: build/Dockerfile
4650
platforms: linux/amd64,linux/arm64
4751
push: true
52+
build-args: |
53+
VERSION=${{ steps.prepare.outputs.tag_name }}
54+
SHORT_COMMIT=${{ steps.prepare.outputs.short_commit }}
55+
DATE=${{ steps.prepare.outputs.date }}
4856
tags: |
4957
golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }}
5058
golangci/golangci-lint:${{ steps.prepare.outputs.major_tag }}
@@ -56,6 +64,10 @@ jobs:
5664
context: .
5765
file: build/Dockerfile.alpine
5866
platforms: linux/amd64,linux/arm64
67+
build-args: |
68+
VERSION=${{ steps.prepare.outputs.tag_name }}
69+
SHORT_COMMIT=${{ steps.prepare.outputs.short_commit }}
70+
DATE=${{ steps.prepare.outputs.date }}
5971
push: true
6072
tags: |
6173
golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }}-alpine

build/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# stage 1 building the code
22
FROM golang:1.15 as builder
33

4+
ARG VERSION
5+
ARG SHORT_COMMIT
6+
ARG DATE
7+
48
COPY / /golangci
59
WORKDIR /golangci
6-
RUN go build -o golangci-lint ./cmd/golangci-lint/main.go
10+
RUN go build -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
711

812
# stage 2
913
FROM golang:1.15

build/Dockerfile.alpine

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# stage 1 building the code
22
FROM golang:1.15-alpine as builder
33

4+
ARG VERSION
5+
ARG SHORT_COMMIT
6+
ARG DATE
7+
48
COPY / /golangci
59
WORKDIR /golangci
6-
RUN CGO_ENABLED=0 go build -o golangci-lint ./cmd/golangci-lint/main.go
10+
RUN go build -ldflags "-s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
711

812
# stage 2
913
FROM golang:1.15-alpine

0 commit comments

Comments
 (0)