From 15745bac2ef50c20d109a6cbe220786b986e0875 Mon Sep 17 00:00:00 2001 From: royalcat Date: Mon, 23 Dec 2024 17:21:58 +0300 Subject: [PATCH] docker multiplatform build --- Dockerfile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e181c8..5331811 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,32 @@ -FROM golang:1.23 AS build +FROM --platform=${BUILDPLATFORM} golang:1.23 AS builder + +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + RUN go build -v std WORKDIR /app COPY go.mod ./ COPY go.sum ./ -RUN go mod download +RUN --mount=type=cache,mode=0777,target=/go/pkg/mod go mod download all COPY ./cmd ./cmd COPY ./pkg ./pkg COPY ./src ./src -RUN go build -tags timetzdata -o /server ./cmd/main.go +RUN --mount=type=cache,mode=0777,target=/go/pkg/mod \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ + go build -tags timetzdata -o /server ./cmd/main.go # run container FROM scratch #Adding root serts for ssl -COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --from=build /server /app/konfa-server +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /server /app/konfa-server WORKDIR /app