Faster multi stage build using cross compilation (#72)

Co-authored-by: maddie <maddie@users.noreply.github.com>
This commit is contained in:
Qasim Mehmood
2026-02-25 15:30:21 +05:00
committed by GitHub
parent aba2be835f
commit faa59b8261
+4 -2
View File
@@ -1,11 +1,13 @@
FROM golang:1.18-alpine AS build_base FROM --platform=$BUILDPLATFORM golang:1.18-alpine AS build_base
RUN apk add --no-cache git gcc ca-certificates libc-dev RUN apk add --no-cache git gcc ca-certificates libc-dev
WORKDIR /build WORKDIR /build
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY ./ ./ COPY ./ ./
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
RUN go build -ldflags "-w -s" -trimpath -o speedtest . ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-w -s" -trimpath -buildvcs=false -o speedtest .
FROM scratch FROM scratch
WORKDIR /app WORKDIR /app