From 939d4194383d0e6bfd22ff73f48544e81830567b Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 19 Oct 2024 21:59:24 +0100 Subject: [PATCH] use multi-stage build --- Dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a60dec..b5bf6b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 +FROM golang:1.21 AS build_image WORKDIR /usr/src/app @@ -8,7 +8,13 @@ RUN go mod download && go mod verify # build binary and place into /usr/local/bin/ COPY . . -RUN go build -v -o /usr/local/bin/q3rcon-proxy ./cmd/q3rcon-proxy/ +RUN CGO_ENABLED=0 GOOS=linux go build -o ./bin/q3rcon-proxy ./cmd/q3rcon-proxy/ + +FROM scratch AS final_image + +WORKDIR /bin/ + +COPY --from=build_image /usr/src/app/bin/q3rcon-proxy . # Command to run when starting the container -ENTRYPOINT [ "q3rcon-proxy" ] \ No newline at end of file +ENTRYPOINT [ "./q3rcon-proxy" ] \ No newline at end of file