Skip to content

Commit

Permalink
Fix compiler and linker flags.
Browse files Browse the repository at this point in the history
- `ARG x y` is poorly defined, so let's avoid it.
- Set ldflags for a release build (strip, omit full paths to source
  files from host system, etc.)
  • Loading branch information
sengi committed May 14, 2024
1 parent efc956f commit b1797bc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ ARG go_tag_suffix=-alpine


FROM --platform=$TARGETPLATFORM ${go_registry}golang:${go_version}${go_tag_suffix} AS builder
ARG TARGETARCH TARGETOS
ARG GOARCH=$TARGETARCH GOOS=$TARGETOS
ARG TARGETARCH
ARG TARGETOS
ARG GOARCH=$TARGETARCH
ARG GOOS=$TARGETOS
ARG CGO_ENABLED=0
ARG GOFLAGS="-trimpath"
ARG go_ldflags="-s -w"

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . ./
RUN go build -o /bin/govuk-exporter main.go
RUN go build -o /bin/govuk-exporter -ldflags="$go_ldflags" main.go


FROM --platform=$TARGETPLATFORM scratch
Expand Down

0 comments on commit b1797bc

Please sign in to comment.