From d85811264086f605977918461e669f3cac025909 Mon Sep 17 00:00:00 2001 From: Qasim Mehmood <18313886+ThisIsQasim@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:41:51 +0500 Subject: [PATCH 1/2] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5270193..7e1a6fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /build COPY go.mod go.sum ./ RUN go mod download COPY ./ ./ -RUN go build -ldflags "-w -s" -trimpath -o speedtest . +RUN go build -ldflags "-w -s" -trimpath -buildvcs=false -o speedtest . FROM alpine:3.16 RUN apk add --no-cache ca-certificates From a5cbbeeac3e31418afdda695c92fcf6479db6041 Mon Sep 17 00:00:00 2001 From: ThisIsQasim <18313886+ThisIsQasim@users.noreply.github.com> Date: Fri, 14 Jun 2024 19:54:58 +0500 Subject: [PATCH 2/2] Faster multi stage build using cross compilation --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e1a6fb..e30d028 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ -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 WORKDIR /build COPY go.mod go.sum ./ RUN go mod download COPY ./ ./ -RUN go build -ldflags "-w -s" -trimpath -buildvcs=false -o speedtest . +ARG TARGETOS TARGETARCH +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-w -s" -trimpath -buildvcs=false -o speedtest . FROM alpine:3.16 RUN apk add --no-cache ca-certificates