|
| 1 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> |
| 3 | +# |
| 4 | +# ECHIDNA HOL4 Containerfile |
| 5 | +# Build: podman build -f .containerization/Containerfile.hol4 -t echidna:hol4 . |
| 6 | +# Seal: selur seal echidna:hol4 |
| 7 | +# Sign: cerro-torre sign echidna:hol4 |
| 8 | +# |
| 9 | +# HOL4: Higher-Order Logic theorem prover, successor to HOL88/HOL90. |
| 10 | +# Strategy: build from source using Poly/ML (Standard ML implementation). |
| 11 | +# Build time: ~30-60 min on 4 cores; needs ~4 GB RAM at peak. |
| 12 | +# Use BuildKit / Podman layer caching aggressively — the HOL4 source checkout |
| 13 | +# and Poly/ML build layers are stable and rarely change. |
| 14 | +# Binary: hol (shell wrapper in HOL4/bin/hol) |
| 15 | + |
| 16 | +# ============================================================================= |
| 17 | +# Stage 1: Rust Builder |
| 18 | +# ============================================================================= |
| 19 | +FROM docker.io/library/rust:1.85-slim-bookworm AS rust-builder |
| 20 | + |
| 21 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 22 | + build-essential \ |
| 23 | + pkg-config \ |
| 24 | + libssl-dev \ |
| 25 | + && rm -rf /var/lib/apt/lists/* |
| 26 | + |
| 27 | +RUN rustup toolchain install nightly && rustup default nightly |
| 28 | + |
| 29 | +WORKDIR /build |
| 30 | + |
| 31 | +COPY Cargo.toml Cargo.lock ./ |
| 32 | +COPY src/rust ./src/rust |
| 33 | +COPY src/interfaces ./src/interfaces |
| 34 | + |
| 35 | +RUN cargo build --release --bin echidna |
| 36 | + |
| 37 | +# ============================================================================= |
| 38 | +# Stage 2a: Poly/ML Builder |
| 39 | +# HOL4 requires Poly/ML >= 5.9; bookworm ships 5.9, which works but 5.10+ is |
| 40 | +# preferred. We build 5.9 from the Debian package for speed; upgrade the ARG |
| 41 | +# below to build from source if a newer version is needed. |
| 42 | +# ============================================================================= |
| 43 | +FROM docker.io/library/debian:bookworm-slim AS polyml-builder |
| 44 | + |
| 45 | +# BuildKit cache hint: Poly/ML sources change rarely — cache this layer hard. |
| 46 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 47 | + build-essential \ |
| 48 | + curl \ |
| 49 | + ca-certificates \ |
| 50 | + git \ |
| 51 | + libgmp-dev \ |
| 52 | + # Poly/ML build dependencies |
| 53 | + libffi-dev \ |
| 54 | + && rm -rf /var/lib/apt/lists/* |
| 55 | + |
| 56 | +WORKDIR /build/polyml |
| 57 | + |
| 58 | +# Download and build Poly/ML from source. |
| 59 | +# Poly/ML 5.9.1 is the latest stable release known to work with HOL4. |
| 60 | +ARG POLYML_VERSION="5.9.1" |
| 61 | +RUN curl -fsSL --retry 3 \ |
| 62 | + "https://github.com/polyml/polyml/releases/download/v${POLYML_VERSION}/polyml-${POLYML_VERSION}.tar.gz" \ |
| 63 | + -o /tmp/polyml.tar.gz \ |
| 64 | + && tar -xzf /tmp/polyml.tar.gz -C /build/polyml --strip-components=1 \ |
| 65 | + && rm /tmp/polyml.tar.gz |
| 66 | + |
| 67 | +RUN ./configure --prefix=/opt/polyml \ |
| 68 | + && make -j"$(nproc)" \ |
| 69 | + && make install \ |
| 70 | + && /opt/polyml/bin/poly --version |
| 71 | + |
| 72 | +# ============================================================================= |
| 73 | +# Stage 2b: HOL4 Builder |
| 74 | +# Long build — runs `poly < tools/smart-configure.sml` then `bin/build`. |
| 75 | +# Layer caching on the git clone keeps re-builds fast when only HOL4 changes. |
| 76 | +# ============================================================================= |
| 77 | +FROM docker.io/library/debian:bookworm-slim AS hol4-builder |
| 78 | + |
| 79 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 80 | + build-essential \ |
| 81 | + git \ |
| 82 | + ca-certificates \ |
| 83 | + libgmp10 \ |
| 84 | + && rm -rf /var/lib/apt/lists/* |
| 85 | + |
| 86 | +# Copy Poly/ML installation |
| 87 | +COPY --from=polyml-builder /opt/polyml /opt/polyml |
| 88 | + |
| 89 | +ENV PATH="/opt/polyml/bin:${PATH}" |
| 90 | + |
| 91 | +WORKDIR /build |
| 92 | + |
| 93 | +# Clone HOL4; use a pinned commit tag for reproducibility. |
| 94 | +# Check https://github.com/HOL-Theorem-Prover/HOL/releases for latest. |
| 95 | +ARG HOL4_VERSION="kananaskis-15" |
| 96 | +RUN git clone --depth 1 --branch "${HOL4_VERSION}" \ |
| 97 | + https://github.com/HOL-Theorem-Prover/HOL.git /build/HOL4 |
| 98 | + |
| 99 | +WORKDIR /build/HOL4 |
| 100 | + |
| 101 | +# Configure HOL4 against the Poly/ML we just built, then build all theories. |
| 102 | +# The smart-configure step auto-detects poly. The `bin/build` step compiles |
| 103 | +# the core theories (takes ~30-60 min on 4 vCPUs). |
| 104 | +RUN poly < tools/smart-configure.sml \ |
| 105 | + && bin/build |
| 106 | + |
| 107 | +# Verify hol wrapper script exists |
| 108 | +RUN test -f /build/HOL4/bin/hol && echo "HOL4 build succeeded" |
| 109 | + |
| 110 | +# ============================================================================= |
| 111 | +# Stage 3: Runtime Image |
| 112 | +# ============================================================================= |
| 113 | +FROM docker.io/library/debian:bookworm-slim |
| 114 | + |
| 115 | +LABEL maintainer="Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>" |
| 116 | +LABEL org.opencontainers.image.source="https://github.com/hyperpolymath/echidna" |
| 117 | +LABEL org.opencontainers.image.description="ECHIDNA + HOL4 - higher-order logic theorem prover" |
| 118 | +LABEL org.opencontainers.image.licenses="PMPL-1.0-or-later" |
| 119 | +LABEL org.opencontainers.image.version="2.3.0" |
| 120 | +LABEL org.opencontainers.image.vendor="hyperpolymath" |
| 121 | + |
| 122 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 123 | + ca-certificates \ |
| 124 | + libssl3 \ |
| 125 | + libgmp10 \ |
| 126 | + libffi8 \ |
| 127 | + && rm -rf /var/lib/apt/lists/* |
| 128 | + |
| 129 | +WORKDIR /app |
| 130 | + |
| 131 | +COPY --from=rust-builder /build/target/release/echidna /app/bin/echidna |
| 132 | + |
| 133 | +# Copy Poly/ML runtime (HOL4 loads ML code via poly at runtime) |
| 134 | +COPY --from=polyml-builder /opt/polyml /opt/polyml |
| 135 | + |
| 136 | +# Copy HOL4 installation (includes pre-built heap images) |
| 137 | +COPY --from=hol4-builder /build/HOL4 /opt/HOL4 |
| 138 | + |
| 139 | +ENV PATH="/app/bin:/opt/polyml/bin:/opt/HOL4/bin:${PATH}" |
| 140 | +ENV HOLDIR="/opt/HOL4" |
| 141 | +ENV ECHIDNA_PROVER_PATH="/opt/HOL4/bin" |
| 142 | + |
| 143 | +RUN mkdir -p /app/proofs /app/config /app/logs |
| 144 | + |
| 145 | +# REST API |
| 146 | +EXPOSE 8000 |
| 147 | +# GraphQL |
| 148 | +EXPOSE 8081 |
| 149 | +# gRPC |
| 150 | +EXPOSE 50051 |
| 151 | + |
| 152 | +# HOL4 cold-start is slow (loads heap image); give generous start-period. |
| 153 | +HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=3 \ |
| 154 | + CMD ["/app/bin/echidna", "--version"] |
| 155 | + |
| 156 | +ENTRYPOINT ["/app/bin/echidna"] |
| 157 | +CMD ["--help"] |
0 commit comments