Skip to content

Commit

Permalink
build(docker): Fix version details in docker image
Browse files Browse the repository at this point in the history
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 <sayboras@yahoo.com>
  • Loading branch information
sayboras committed Oct 26, 2020
1 parent f414375 commit 06fa9d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tag.yml
Expand Up @@ -45,6 +45,10 @@ jobs:
file: build/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ steps.prepare.outputs.tag_name }}
SHORT_COMMIT=${GITHUB_SHA::8}
DATE=$(date '+%Y-%m-%dT%H:%M:%SZ')
tags: |
golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }}
golangci/golangci-lint:${{ steps.prepare.outputs.major_tag }}
Expand All @@ -56,6 +60,10 @@ jobs:
context: .
file: build/Dockerfile.alpine
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.prepare.outputs.tag_name }}
SHORT_COMMIT=${GITHUB_SHA::8}
DATE=$(date '+%Y-%m-%dT%H:%M:%SZ')
push: true
tags: |
golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }}-alpine
Expand Down
6 changes: 5 additions & 1 deletion build/Dockerfile
@@ -1,9 +1,13 @@
# stage 1 building the code
FROM golang:1.15 as builder

ARG VERSION
ARG SHORT_COMMIT
ARG DATE

COPY / /golangci
WORKDIR /golangci
RUN go build -o golangci-lint ./cmd/golangci-lint/main.go
RUN go build -s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE -o golangci-lint ./cmd/golangci-lint/main.go

# stage 2
FROM golang:1.15
Expand Down
6 changes: 5 additions & 1 deletion build/Dockerfile.alpine
@@ -1,9 +1,13 @@
# stage 1 building the code
FROM golang:1.15-alpine as builder

ARG VERSION
ARG SHORT_COMMIT
ARG DATE

COPY / /golangci
WORKDIR /golangci
RUN CGO_ENABLED=0 go build -o golangci-lint ./cmd/golangci-lint/main.go
RUN go build -s -w -X main.version=$VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE -o golangci-lint ./cmd/golangci-lint/main.go

# stage 2
FROM golang:1.15-alpine
Expand Down

0 comments on commit 06fa9d5

Please sign in to comment.