From 817f317b03e04879ab0ce830ea59d447f3423175 Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Sat, 8 Feb 2025 02:17:20 -0600 Subject: [PATCH] Multi arch --- Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 29c31a0..fb12ddc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23.2-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.23.2-alpine AS builder WORKDIR /app @@ -19,14 +19,22 @@ RUN mkdir -p /app/public/css # Generate assets and build with optimizations SHELL ["/bin/bash", "-c"] + +# Platform-specific builds +ARG TARGETPLATFORM RUN cd /app && make generate && \ - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ + case "${TARGETPLATFORM}" in \ + "linux/amd64") GOARCH=amd64 ;; \ + "linux/arm64") GOARCH=arm64 ;; \ + *) GOARCH=amd64 ;; \ + esac && \ + CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build \ -ldflags='-s -w -extldflags "-static"' \ -tags netgo,osusergo \ -o /go/bin/app # Final stage -FROM scratch +FROM --platform=$TARGETPLATFORM scratch # Copy static files and assets COPY --from=builder /app/public/css/styles.css /public/css/styles.css