File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -96,29 +96,28 @@ func (d *Golang) GenerateDockerfile(path string) ([]byte, error) {
9696
9797var golangTemplate = strings .TrimSpace (`
9898ARG VERSION={{.Version}}
99- ARG BUILDPLATFORM=linux
99+ ARG BUILDPLATFORM=linux/amd64
100100FROM --platform=${BUILDPLATFORM} golang:${VERSION} AS base
101+
102+ FROM base AS deps
101103WORKDIR /go/src/app
102- ARG TARGETOS=linux
103- ARG TARGETARCH=arm64
104- ARG CGO_ENABLED=0
104+ COPY go.mod* go.sum* ./
105+ # GOPROXY is used to specify the module proxy to use.
105106ARG GOPROXY=direct
106-
107- COPY . .
108107ENV GOPROXY=${GOPROXY}
109- RUN if [ -f go.mod ]; then go mod download; fi
108+ RUN if [ -f go.mod ]; then go mod download && go mod tidy ; fi
110109
111- FROM base AS build
110+ FROM deps AS build
112111WORKDIR /go/src/app
112+
113+ COPY . .
114+
115+ ARG PACKAGE={{.Package}}
113116ARG TARGETOS=linux
114- ARG TARGETARCH=arm64
117+ ARG TARGETARCH=amd64
115118ARG CGO_ENABLED=0
116- ARG PACKAGE={{.Package}}
117- ARG GOPROXY=direct
118119# -trimpath removes the absolute path to the source code in the binary
119120# -ldflags="-s -w" removes the symbol table and debug information from the binary
120- # CGO_ENABLED=0 disables the use of cgo
121- ENV GOPROXY=${GOPROXY}
122121RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -o /go/bin/app "${PACKAGE}"
123122
124123FROM debian:stable-slim
@@ -130,6 +129,7 @@ RUN chown -R nonroot:nonroot /app
130129COPY --chown=nonroot:nonroot --from=build /go/bin/app .
131130
132131ENV PORT=8080
132+ EXPOSE ${PORT}
133133USER nonroot:nonroot
134134CMD ["/app/app"]
135135` )
You can’t perform that action at this time.
0 commit comments