From a7037a27bf29898782c52aaab93fafe754e6755a Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Fri, 11 Oct 2024 11:28:06 +0800 Subject: [PATCH] update Dockerfile --- Dockerfile | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d608d7..e658403 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,27 @@ -FROM golang:1.23-alpine3.20 AS builder +FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 AS builder -RUN apk add --no-cache musl-dev git gcc +ARG TARGETOS +ARG TARGETARCH -ADD . /src +# RUN apk add --no-cache musl-dev git gcc -WORKDIR /src +ENV CGO_ENABLED=0 -RUN cd cmd/gost && go env && go build +RUN go env + +WORKDIR /app + +# Cache the download before continuing +COPY go.mod go.mod +COPY go.sum go.sum +RUN go mod download + +COPY . . + +WORKDIR /app/cmd/gost + +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build FROM alpine:3.20 @@ -15,6 +30,6 @@ RUN apk add --no-cache iptables WORKDIR /bin/ -COPY --from=builder /src/cmd/gost/gost . +COPY --from=builder /app/cmd/gost/gost . ENTRYPOINT ["/bin/gost"] \ No newline at end of file