ARG RUST_TAG=1.98.1-alpine3.24
FROM rust:${RUST_TAG} AS builder

ARG BUILD_BASE_VERSION=0.5-r4
RUN --mount=type=cache,sharing=locked,target=/var/cache/apk \
    apk add --update build-base=${BUILD_BASE_VERSION}

RUN \
    # This one would be nice if it worked:
    # --mount=type=bind,source=.,target=/root/app \
    # Use this one if there's a hard to track down "read-only filesystem" error:
    --mount=type=bind,source=.,target=/root/app,rw \

    --mount=type=cache,sharing=private,target=/root/app/target \
    --mount=type=cache,target=/usr/local/cargo/git/db \
    --mount=type=cache,target=/usr/local/cargo/registry/ \
    cd /root/app && \
    cargo build --release && \
    cp target/release/cloud-llms /root/program

FROM scratch AS runner

COPY --from=builder /root/program /program

ENTRYPOINT ["/program"]
