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.
This commit is contained in:
gigirassy
2025-11-01 02:40:15 +01:00
parent 30e42e9886
commit f5b10d01e6

View File

@@ -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"]