|
| 1 | +# Multi-stage Dockerfile for the polyglot scheduling stack |
| 2 | +# Stage 1: builder and test runner |
| 3 | +FROM ubuntu:22.04 AS builder |
| 4 | + |
| 5 | +ENV DEBIAN_FRONTEND=noninteractive |
| 6 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 7 | + ca-certificates curl git \ |
| 8 | + ghc cabal-install \ |
| 9 | + swi-prolog \ |
| 10 | + build-essential \ |
| 11 | + && rm -rf /var/lib/apt/lists/* |
| 12 | + |
| 13 | +WORKDIR /app |
| 14 | +COPY . /app |
| 15 | + |
| 16 | +# Install Haskell dependencies required by GeneticSchedule.hs |
| 17 | +RUN cabal update && cabal install aeson --lib |
| 18 | + |
| 19 | +# Build the Haskell scheduler as a native binary for faster startup |
| 20 | +RUN ghc -O2 -threaded haskell/GeneticSchedule.hs -o /app/genetic-schedule |
| 21 | + |
| 22 | +# Run smoke tests during the build to ensure the image is healthy |
| 23 | +# If tests are not desired, pass --target runtime when building. |
| 24 | +RUN bash tests/run_all.sh || (echo "Tests failed during Docker build" && exit 1) |
| 25 | + |
| 26 | +# Stage 2: runtime image with just what we need |
| 27 | +FROM ubuntu:22.04 AS runtime |
| 28 | + |
| 29 | +ENV DEBIAN_FRONTEND=noninteractive |
| 30 | +# libgmp is required by GHC-built binaries; include swipl runtime as optional tool and a minimal JRE |
| 31 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 32 | + libgmp10 \ |
| 33 | + swi-prolog-nox \ |
| 34 | + ca-certificates \ |
| 35 | + openjdk-17-jre-headless \ |
| 36 | + && rm -rf /var/lib/apt/lists/* |
| 37 | + |
| 38 | +WORKDIR /app |
| 39 | +# Copy compiled binary and necessary assets |
| 40 | +COPY --from=builder /app/genetic-schedule /app/genetic-schedule |
| 41 | +COPY --from=builder /app/prolog /app/prolog |
| 42 | +COPY --from=builder /app/sample-request.json /app/sample-request.json |
| 43 | + |
| 44 | +# Copy startup script that decides whether to run Java or the Haskell scheduler |
| 45 | +COPY start.sh /app/start.sh |
| 46 | +RUN chmod +x /app/start.sh |
| 47 | + |
| 48 | +# Document ENV that Java service would use if run in this container later |
| 49 | +ENV SCHEDULER_HS_CMD=/app/genetic-schedule \ |
| 50 | + SCHEDULER_HS_SCRIPT="" |
| 51 | + |
| 52 | +# Expose Spring Boot default port (used when running the Java app) |
| 53 | +EXPOSE 8080 |
| 54 | + |
| 55 | +# Default entrypoint delegates to the start script |
| 56 | +ENTRYPOINT ["/app/start.sh"] |
0 commit comments