Skip to content

Commit f8ffb61

Browse files
committed
fix(): optimise multi arch build
Signed-off-by: gourishkb <gourish@aveshasystems.com>
1 parent 09959c5 commit f8ffb61

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Dockerfile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
FROM golang:1.24.2 AS builder
1+
# syntax=docker/dockerfile:1.4
2+
FROM --platform=$BUILDPLATFORM golang:1.24.2 AS builder
3+
4+
ARG BUILDPLATFORM
5+
ARG TARGETPLATFORM
6+
ARG TARGETARCH
7+
ARG TARGETOS=linux
28

39
WORKDIR /workspace
10+
411
# Copy the Go Modules manifests
5-
COPY go.mod go.mod
6-
COPY go.sum go.sum
12+
COPY go.mod go.sum ./
713

814
# Copy the go source
915
COPY main.go main.go
1016
COPY plugin/ plugin/
1117
COPY vendor/ vendor/
1218

13-
ARG TARGETPLATFORM
14-
ARG TARGETARCH
15-
ARG TARGETOS
16-
17-
# Build
18-
RUN go env -w GOPRIVATE=github.org/kubeslice && \
19-
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on go build -mod=vendor -a -o coredns main.go
19+
# Build with cross-compilation
20+
RUN --mount=type=cache,target=/root/.cache/go-build \
21+
--mount=type=cache,target=/go/pkg \
22+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GO111MODULE=on \
23+
go build -mod=vendor -ldflags="-w -s" -trimpath -o coredns main.go
2024

2125
FROM gcr.io/distroless/static:nonroot
2226

0 commit comments

Comments
 (0)