From f5b10d01e68d5bd7b5c7885040628ee2bedaf174 Mon Sep 17 00:00:00 2001 From: gigirassy Date: Sat, 1 Nov 2025 02:40:15 +0100 Subject: [PATCH] Replace runtime stage with scratch An Alpine runtime is not necessary for a simple go binary like this with zero other folders/data, and using scratch reduces memory significantly as all that'll be running is the binary. --- Dockerfile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba2f9f2..847f355 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,24 @@ FROM --platform=$BUILDPLATFORM golang:alpine AS build ARG TARGETARCH - WORKDIR /src + RUN apk --no-cache add git + +COPY go.mod go.sum ./ +RUN go mod download + COPY . . -ENV GOPRIVATE=codeberg.org/aryak/libmozhi -#RUN go mod download RUN go run github.com/swaggo/swag/cmd/swag@latest init --parseDependency -RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /src/mozhi -FROM alpine:3.16 AS bin +ENV CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} +RUN go build -ldflags="-s -w" -o /src/mozhi ./ # adjust path if needed +FROM scratch AS runtime WORKDIR /app -COPY --from=build /src/mozhi . + +COPY --from=build /src/mozhi /app/mozhi EXPOSE 3000 - -CMD ["/app/mozhi", "serve"] +ENTRYPOINT ["/app/mozhi", "serve"]