mirror of
https://codeberg.org/gigirassy/pinata
synced 2026-08-30 23:37:40 +00:00
Reduce memory usage again
How itty can we go?
This commit is contained in:
+6
-15
@@ -1,36 +1,27 @@
|
|||||||
# syntax=docker/dockerfile:1.4
|
# syntax=docker/dockerfile:1.4
|
||||||
#
|
|
||||||
# Multi-arch build (use BuildKit/docker buildx). Produces a tiny scratch image.
|
|
||||||
#
|
|
||||||
FROM --platform=$BUILDPLATFORM golang:1.24.8-alpine AS builder
|
FROM --platform=$BUILDPLATFORM golang:1.24.8-alpine AS builder
|
||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG TARGETVARIANT
|
ARG TARGETVARIANT
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Cache deps
|
|
||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
RUN apk add --no-cache ca-certificates git && go mod download
|
RUN apk add --no-cache ca-certificates git && go mod download
|
||||||
|
|
||||||
# Copy sources and build a tiny static binary for the target platform
|
|
||||||
COPY . .
|
COPY . .
|
||||||
# Build static binary; CGO disabled so we can use scratch
|
|
||||||
RUN CGO_ENABLED=0 \
|
RUN CGO_ENABLED=0 \
|
||||||
GOOS=${TARGETOS:-linux} \
|
GOOS=${TARGETOS:-linux} \
|
||||||
GOARCH=${TARGETARCH:-amd64} \
|
GOARCH=${TARGETARCH:-amd64} \
|
||||||
go build -trimpath -ldflags="-s -w" -o /pinata ./main.go
|
go build -trimpath \
|
||||||
|
-ldflags="-s -w -extldflags '-static' -buildid=''" \
|
||||||
|
-gcflags="all=-l" \
|
||||||
|
-o /pinata ./main.go
|
||||||
|
|
||||||
# Final stage: minimal runtime
|
|
||||||
FROM scratch AS runtime
|
FROM scratch AS runtime
|
||||||
# copy binary
|
|
||||||
COPY --from=builder /pinata /pinata
|
COPY --from=builder /pinata /pinata
|
||||||
# copy CA bundle so TLS works
|
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
|
||||||
# run as a non-root numeric UID (no passwd required in scratch)
|
|
||||||
USER 65532
|
USER 65532
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
ENV GOMEMLIMIT=8MiB \
|
||||||
|
GOGC=20
|
||||||
ENTRYPOINT ["/pinata"]
|
ENTRYPOINT ["/pinata"]
|
||||||
|
|||||||
Reference in New Issue
Block a user