# DEV / LOCAL ONLY (ADR-038). This recompiles from source with the stratumiops
# build-context — convenient for local single-arch image builds. It is NOT the
# release path: the published multi-arch runnable image is assembled by
# `.woodpecker/release.yml` with buildah FROM the cross-compiled musl binaries
# (no recompile, no buildx/QEMU). Regenerate that pipeline with
# `ore workflow generate --layer release`.

ARG IMAGE_BASE=reg.librecloud.online/lamina
ARG RUST_VERSION=1.89

# Pull nickel binary from the lamina nickel layer — named stage makes ARG expansion reliable
FROM ${IMAGE_BASE}/nickel:${RUST_VERSION} AS nickel-layer

# Builder: lamina rust layer provides cargo, rustc, sccache, cargo-chef
FROM ${IMAGE_BASE}/rust:${RUST_VERSION} AS builder

WORKDIR /build
ENV CARGO_TARGET_DIR=/build/target

# stratumiops source injected via --build-context stratumiops=../stratumiops
# Resolves to /stratumiops — matches ../../../stratumiops relative path from crates/ontoref-daemon/
COPY --from=stratumiops . /stratumiops

COPY Cargo.toml Cargo.lock ./
COPY crates ./crates

RUN cargo build --release --bin ontoref-daemon

# Runtime: minimal base + nickel (for NCL export at runtime) + daemon binary
FROM alpine:3.21

RUN apk add --no-cache ca-certificates

COPY --from=nickel-layer /usr/local/bin/nickel /usr/local/bin/nickel
COPY --from=builder /build/target/release/ontoref-daemon /usr/local/bin/ontoref-daemon

EXPOSE 7891

ENTRYPOINT ["ontoref-daemon"]
