Skip to content

Commit faa59b8

Browse files
ThisIsQasimmaddie
andauthored
Faster multi stage build using cross compilation (#72)
Co-authored-by: maddie <maddie@users.noreply.github.com>
1 parent aba2be8 commit faa59b8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM golang:1.18-alpine AS build_base
1+
FROM --platform=$BUILDPLATFORM golang:1.18-alpine AS build_base
22
RUN apk add --no-cache git gcc ca-certificates libc-dev
33
WORKDIR /build
44
COPY go.mod go.sum ./
55
RUN go mod download
66
COPY ./ ./
7+
78
ENV CGO_ENABLED=0
8-
RUN go build -ldflags "-w -s" -trimpath -o speedtest .
9+
ARG TARGETOS TARGETARCH
10+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-w -s" -trimpath -buildvcs=false -o speedtest .
911

1012
FROM scratch
1113
WORKDIR /app

0 commit comments

Comments
 (0)