From 245a16fe9b1912b3e7f981c0805cbe8ea6151fc7 Mon Sep 17 00:00:00 2001 From: Owen Date: Wed, 27 May 2026 22:37:44 +0200 Subject: [PATCH] run backend in docker container --- Dockerfile | 30 ++++++++++++++++++++++++++++++ bin/main.ml | 3 ++- docker-compose.yml | 13 +++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a4e6092 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# --- STAGE 1: Build the native OCaml binary --- +FROM ocaml/opam:debian-12-ocaml-5.4 AS builder +USER opam +WORKDIR /app +COPY --chown=opam:opam dune-project ./ +RUN opam update && opam install -y dune dream +COPY --chown=opam:opam . . +RUN opam exec -- dune build bin/main.exe + +# --- STAGE 2: Lightweight runtime environment --- +FROM debian:12-slim +WORKDIR /app + +# Install native system dependencies and a minimal TeX Live profile +RUN apt-get update && apt-get install -y --no-install-recommends \ + libssl3 \ + libev4 \ + ca-certificates \ + # texlive-latex-base \ + # texlive-latex-recommended \ + # texlive-fonts-recommended \ + # # tlmgr is the TeX Live package manager; we use it to grab chess assets + # texlive-games \ + && rm -rf /var/lib/apt/lists/* + +# Copy the compiled native OCaml binary from Stage 1 +COPY --from=builder /app/_build/default/bin/main.exe ./server + +EXPOSE 8080 +CMD ["./server"] \ No newline at end of file diff --git a/bin/main.ml b/bin/main.ml index 9234fa1..60ad483 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,5 +1,6 @@ let () = - Dream.run @@ Dream.logger + Dream.run ~interface:"0.0.0.0" ~port:8080 + @@ Dream.logger @@ Dream.router [ Dream.get "/" (fun _ -> Dream.html "API Docs"); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c5ff9cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + chess-scribe-api: + build: + context: . + dockerfile: Dockerfile + container_name: chess-scribe-api + restart: unless-stopped + + ports: + - "8080:8080" + + environment: + - DREAM_ENV=production \ No newline at end of file