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.
25 lines
489 B
Docker
25 lines
489 B
Docker
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 . .
|
|
|
|
RUN go run github.com/swaggo/swag/cmd/swag@latest init --parseDependency
|
|
|
|
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 /app/mozhi
|
|
|
|
EXPOSE 3000
|
|
ENTRYPOINT ["/app/mozhi", "serve"]
|