-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (53 loc) · 2.31 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (53 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## Build and runtime image for the Haskell tersmu parser
##
## The original single-stage image was huge because it shipped:
## - the full GHC+cabal toolchain (from haskell:9.8)
## - cabal store/build artifacts
## - the whole source tree
##
## This multi-stage Dockerfile keeps all build tooling in the builder stage,
## then copies only the installed binaries + data-files into a slim runtime.
FROM haskell:9.8 AS builder
## Additional tools needed at build time
RUN apt-get update && apt-get install -y --no-install-recommends \
darcs \
gcc \
make \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
## --- Cabal dependency caching ---
## Copy only the cabal file first so Docker can cache dependency fetch/build.
## Changing source files won't invalidate this layer unless dependencies change.
COPY tersmu.cabal ./tersmu.cabal
RUN cabal update \
&& cabal build --only-dependencies exe:tersmu exe:tersmu-server
## Now copy the rest of the working tree (this layer changes frequently).
COPY . .
## Fetch/build the patched Pappy tool, then generate the Haskell modules
## required by cabal (Lojban.hs, Morphology.hs, Pappy/Parse.hs).
RUN make pappy/pappy/pappy \
&& make Pappy/Parse.hs Lojban.hs Morphology.hs
## Install just the executables into a clean directory so we can copy them
## into a tiny runtime image. This avoids shipping /root/.cabal (huge store).
RUN mkdir -p /opt/tersmu/bin \
&& cabal install \
exe:tersmu \
exe:tersmu-server \
--install-method=copy \
--installdir=/opt/tersmu/bin \
--overwrite-policy=always
## Optional: strip symbols to reduce binary size (safe to ignore if strip missing)
RUN strip /opt/tersmu/bin/tersmu /opt/tersmu/bin/tersmu-server || true
FROM debian:bookworm-slim AS runtime
## Runtime shared libraries commonly needed by GHC-produced binaries.
## (Exact set depends on linking; these are small compared to GHC itself.)
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libgmp10 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /opt/tersmu/bin/tersmu /usr/local/bin/tersmu
COPY --from=builder /opt/tersmu/bin/tersmu-server /usr/local/bin/tersmu-server
EXPOSE 8080
## By default, run the HTTP REST API. To run the CLI instead:
## docker run --rm -it --entrypoint tersmu tersmu examples/1.jbo
CMD ["tersmu-server"]