From 7488c6987d3a7ef885c45811774964ac89264837 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Mon, 20 May 2024 22:17:09 +0800 Subject: [PATCH] feat: add build-arg into the golang dockerfile template (#13) Co-authored-by: rick --- runtime/golang.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/golang.go b/runtime/golang.go index ee5ebff..8c9e71c 100644 --- a/runtime/golang.go +++ b/runtime/golang.go @@ -102,8 +102,10 @@ WORKDIR /go/src/app ARG TARGETOS=linux ARG TARGETARCH=arm64 ARG CGO_ENABLED=0 +ARG GOPROXY=direct COPY . . +ENV GOPROXY=${GOPROXY} RUN if [ -f go.mod ]; then go mod download; fi FROM base AS build @@ -112,9 +114,11 @@ ARG TARGETOS=linux ARG TARGETARCH=arm64 ARG CGO_ENABLED=0 ARG PACKAGE={{.Package}} +ARG GOPROXY=direct # -trimpath removes the absolute path to the source code in the binary # -ldflags="-s -w" removes the symbol table and debug information from the binary # CGO_ENABLED=0 disables the use of cgo +ENV GOPROXY=${GOPROXY} RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o /go/bin/app "${PACKAGE}" FROM debian:stable-slim