Skip to content

Commit 3b5b79e

Browse files
authored
fix: Enhance Dockerfile for multi-platform support (#566)
Updated Dockerfile to support multi-platform builds and improved caching for Go dependencies.
1 parent 4788153 commit 3b5b79e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
FROM golang:1.26-alpine AS builder
1+
# syntax=docker/dockerfile:1
2+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
23

34
WORKDIR /build
45

5-
RUN apk update && apk add upx
6+
# Install build dependencies
7+
RUN apk update && apk add --no-cache upx git
68

79
ARG VERSION=main
10+
ARG TARGETPLATFORM
11+
ARG BUILDPLATFORM
12+
ARG TARGETOS
13+
ARG TARGETARCH
14+
815
ENV GO111MODULE=on \
9-
CGO_ENABLED=0 \
10-
GOOS=linux
16+
CGO_ENABLED=0
17+
1118
COPY . .
1219

13-
RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/bakito/k8s-event-logger-operator/version.Version=${VERSION}" -o k8s-event-logger && \
14-
upx -q k8s-event-logger
20+
RUN --mount=type=cache,target=/go/pkg/mod \
21+
--mount=type=cache,target=/root/.cache/go-build \
22+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
23+
go build \
24+
-a \
25+
-installsuffix cgo \
26+
-ldflags="-w -s -X github.com/bakito/k8s-event-logger-operator/version.Version=${VERSION}" \
27+
-o k8s-event-logger . && \
28+
upx -q k8s-event-logger
1529

1630
# application image
1731
FROM scratch

0 commit comments

Comments
 (0)