Skip to content

Commit

Permalink
feat: add build-arg into the golang dockerfile template (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored May 20, 2024
1 parent 359c008 commit 7488c69
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions runtime/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7488c69

Please sign in to comment.