FROM golang:1.25-alpine AS source


WORKDIR /src

RUN apk add --no-cache ca-certificates git ffmpeg poppler-utils 7zip xz

COPY go.mod go.sum ./
RUN go mod download

COPY . .

FROM source AS test
# Test packages create independent SQLite stores. Serialize packages to avoid
# concurrent server/store initialization exhausting the shared runner's I/O.
# Keep production database deadlines and the complete test suite unchanged.
# Temporary test databases use bounded RAM-backed storage rather than the
# runner's overlay filesystem. Compiler temporary files remain on disk.
RUN --mount=type=tmpfs,target=/test-tmp,size=2147483648 \
    TMPDIR=/test-tmp GOTMPDIR=/tmp go test -p 1 ./...

FROM source AS runtime
RUN go build -o /pageswiki ./cmd/pageswiki

EXPOSE 8081

CMD ["/pageswiki"]
