Skip to content

Commit 09e971e

Browse files
committed
chore(docker): Simplify cross-compilation using tonistiigi/xx
1 parent 83a2008 commit 09e971e

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

Dockerfile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
#syntax=docker/dockerfile:1
22

3+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.6.1 AS xx
4+
35
FROM --platform=$BUILDPLATFORM golang:1.24.0-alpine AS build
46
WORKDIR /app
57

8+
COPY --from=xx / /
9+
610
COPY go.mod go.sum ./
711
RUN go mod download
812

913
COPY . .
1014

11-
# Set Golang build envs based on Docker platform string
1215
ARG TARGETPLATFORM
13-
RUN --mount=type=cache,target=/root/.cache <<EOT
14-
set -eux
15-
case "$TARGETPLATFORM" in
16-
'linux/amd64') export GOARCH=amd64 ;;
17-
'linux/arm/v6') export GOARCH=arm GOARM=6 ;;
18-
'linux/arm/v7') export GOARCH=arm GOARM=7 ;;
19-
'linux/arm64') export GOARCH=arm64 ;;
20-
*) echo "Unsupported target: $TARGETPLATFORM" && exit 1 ;;
21-
esac
22-
go build -ldflags='-w -s' -trimpath
23-
EOT
16+
RUN --mount=type=cache,target=/root/.cache \
17+
CGO_ENABLED=0 xx-go build -ldflags='-w -s' -trimpath
2418

2519

2620
FROM gcr.io/distroless/static:nonroot

0 commit comments

Comments
 (0)