-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (42 loc) · 1.42 KB
/
Copy pathDockerfile
File metadata and controls
48 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# syntax=docker/dockerfile:1
ARG GO_VERSION="1.26.5"
ARG ALPINE_VERSION="3.23"
ARG XX_VERSION="1.9.0"
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
# osxcross contains the MacOSX cross toolchain for xx
FROM crazymax/osxcross:26.1-debian AS osxcross
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder-base
COPY --from=xx / /
RUN apk add --no-cache clang zig musl-dev gcc
WORKDIR /src
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download
ENV CGO_ENABLED=1
FROM builder-base AS builder
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/var/cache/apk,id=apk-$TARGETPLATFORM,sharing=locked \
xx-apk add musl-dev gcc
COPY . ./
RUN --mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
--mount=type=cache,target=/root/.cache/go-build,id=go-build-$TARGETPLATFORM \
--mount=type=cache,target=/go/pkg/mod <<EOT
set -ex
if [ "$TARGETOS" = "darwin" ]; then
export CGO_ENABLED=1
else
export CGO_ENABLED=0
fi
EXT=""
if [ "$TARGETOS" = "windows" ]; then
EXT=".exe"
fi
xx-go build -trimpath -ldflags "-s -w" -o /binaries/gogo-$TARGETOS-$TARGETARCH$EXT .
xx-verify /binaries/gogo-$TARGETOS-$TARGETARCH$EXT
EOT
FROM scratch
COPY --from=builder /binaries .