# syntax=docker/dockerfile:1

FROM golang:1.26-bookworm AS builder

ARG VERSION=dev
WORKDIR /src

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

COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
    go build -trimpath -ldflags="-s -w" \
    -o /out/ingestion ./cmd/server

FROM alpine:3.21

COPY --from=builder /out/ingestion /usr/local/bin/ingestion

RUN addgroup -S ingestion && adduser -S -G ingestion ingestion

WORKDIR /app

# brain/ is writable state — mount a PersistentVolume here
VOLUME /app/brain

ENV INGEST_BRAIN_DIR=/app/brain
ENV INGEST_PORT=3300

USER ingestion

EXPOSE 3300

ENTRYPOINT ["/usr/local/bin/ingestion"]
