# OCaml SX kernel build image.
#
# Produces a statically-linked sx_server binary that can be COPY'd
# into any service's Docker image.
#
# Usage:
#   docker build -t sx-kernel -f hosts/ocaml/Dockerfile .
#   docker build --target=export -o hosts/ocaml/_build/export -f hosts/ocaml/Dockerfile .

FROM ocaml/opam:debian-12-ocaml-5.2 AS build

USER opam
WORKDIR /home/opam/sx

# Copy only what's needed for the OCaml build
COPY --chown=opam:opam hosts/ocaml/dune-project ./
COPY --chown=opam:opam hosts/ocaml/lib/ ./lib/
COPY --chown=opam:opam hosts/ocaml/bin/ ./bin/

# Build the server binary
RUN eval $(opam env) && dune build bin/sx_server.exe

# Export stage — just the binary
FROM scratch AS export
COPY --from=build /home/opam/sx/_build/default/bin/sx_server.exe /sx_server
