# Lean image for the hodge-conjecture `build` check (checks/build.py): everything before the compile. # # docker/build.sh builds this file with the tree of the project's main as the context (shoal-hodge-lean:3344da59-base), # then compiles the project's own 33,429 files in a container of it and commits that container as # shoal-hodge-lean:3344da59 (docker/README.md). A compile of hours does not belong in a layer that one failure throws # away. # # The context is the project's main, not this folder: the project is the import closure of the CM Hodge challenge and # solution inside lean/ of openai/math at 3344da59 (upstream.json), with this project's own lakefile.toml and # lake-manifest.json, which require Mathlib alone. Cloning openai/math would bring its lakefile.lean and the 59 # packages of its manifest, of which the proof imports Mathlib alone. The check runs with --network none: nothing is # downloaded at check time. # # Every pin is a full commit hash or a checksum in an ARG below, and each download is checked against it. FROM ubuntu:24.04 # --- Where the downloads come from ------------------------------------------ # The defaults are each project's own servers. From Beijing (docker/build.sh with MIRRORS=cn): the Ubuntu archive by # plain http from Aliyun (ca-certificates is not installed yet at the first apt step), the Lean toolchain from SJTU's # mirror of its releases, Go from Aliyun, Go modules from goproxy.cn, Rust and its crates from rsproxy.cn, the git # fetches through gh-proxy.com. # raw.githubusercontent.com is not used: Beijing cannot reach it. ARG APT_MIRROR= ARG LEAN_DL=https://github.com/leanprover/lean4/releases/download ARG GO_DL=https://go.dev/dl ARG GOPROXY=https://proxy.golang.org,direct ARG RUST_DIST=https://static.rust-lang.org ARG CARGO_MIRROR= # A proxy in front of github.com for the git fetches (docker/clone-at) and elan's release, e.g. # https://gh-proxy.com/https://github.com ARG GITHUB_MIRROR= # --- Pins ------------------------------------------------------------------- # openai/math, whose lean/ folder the project starts from, and its lean-toolchain at that commit, with the SHA-256 # GitHub lists for the release's lean-4.34.1-linux.tar.zst. ARG UPSTREAM_COMMIT=3344da59991ed94f9ba711217b29c1d760badfa6 ARG TOOLCHAIN=leanprover/lean4:v4.34.1 ARG LEAN_SHA256=47bf4bbd78f70c2e9670598ab7124d92b6efb7330ff33e5fbb4030f6fd72e4e4 # From the project's lake-manifest.json (openai/math's pins at that commit). Every package is cloned at the manifest's # commit; these three are also checked here. ARG MATHLIB_COMMIT=d13f23b723b8a846827a245b89c10fc7d3f11612 ARG BATTERIES_COMMIT=f2effa3d803fda822b1f97b806c47cf2adfbcbc2 ARG AESOP_COMMIT=355695d523e41d0554926416cba2a2b3544fbbc9 # Comparator and its exporter, built here and not as packages of the project. Lean v4.34.1 does not ship # `lake comparator` (v4.35.0 and later do), so the standalone tools are used, at their v4.34.0 tags. ARG COMPARATOR_REV=d03acab154d269c06e60e4de7e4cc85deebff94b ARG LEAN4EXPORT_REV=076e8e57707e813375e8f9da8bf989799ace9680 # Comparator's sandbox (landrun 0.1.18) and the second kernel (nanoda_lib 0.4.18), as the navier-stokes and # poincare-conjecture images pin them. ARG LANDRUN_REV=811cfff51ceaf3d9843708aa6d22e9b84ccac8b4 ARG NANODA_REV=079049d584b2aed2b0172218164082f4fc6eede2 # Build tools for landrun (go.mod asks for Go 1.24) and nanoda (Rust), used here and removed. ARG GO_VERSION=1.24.13 ARG GO_SHA256=1fc94b57134d51669c72173ad5d49fd62afb0f1db9bf3f798fd98ee423f8d730 ARG RUST_VERSION=1.100.1 # --- System packages -------------------------------------------------------- # python3 runs the check; curl and zstd are what Lake and Mathlib's cache tool use. ENV DEBIAN_FRONTEND=noninteractive RUN if [ -n "$APT_MIRROR" ]; then sed -i "s#http://archive.ubuntu.com/ubuntu#$APT_MIRROR#; s#http://security.ubuntu.com/ubuntu#$APT_MIRROR#" /etc/apt/sources.list.d/ubuntu.sources; fi \ && apt-get update && apt-get install -y --no-install-recommends \ ca-certificates curl git python3 build-essential zstd \ && rm -rf /var/lib/apt/lists/* # The check runs the commit's build as `nobody`; let git (and Lake, which calls git in each package) read every # repository in the image. clone-at fetches one pinned commit of a repository, with retries (docker/clone-at). COPY docker/clone-at /usr/local/bin/clone-at RUN git config --system --add safe.directory '*' && chmod 755 /usr/local/bin/clone-at # --- Lean ------------------------------------------------------------------- # elan 4.1.2 from its GitHub release, checksum-verified. The toolchain as its release tarball, likewise, unpacked where elan keeps a # toolchain of that name: `elan toolchain install` takes it from releases.lean-lang.org, which redirects to GitHub's # release, and from Beijing that download stalls (12-02: 1.7 MB in two minutes); LEAN_DL lets a mirror serve the file. ENV ELAN_HOME=/opt/elan ENV PATH=/usr/local/bin:/opt/elan/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin ARG ELAN_SHA256=f81c2e48c1588d4612cd2c8851947898a45ac8d72748a07dff3a5694f1cf589b RUN curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 --speed-limit 1000 --speed-time 30 \ "${GITHUB_MIRROR:-https://github.com}/leanprover/elan/releases/download/v4.1.2/elan-x86_64-unknown-linux-gnu.tar.gz" -o /tmp/elan.tgz \ && echo "${ELAN_SHA256} /tmp/elan.tgz" | sha256sum -c - \ && tar -xzf /tmp/elan.tgz -C /tmp && /tmp/elan-init -y --no-modify-path --default-toolchain none && rm /tmp/elan-init /tmp/elan.tgz RUN v="${TOOLCHAIN#*:v}" && dir="/opt/elan/toolchains/$(echo "${TOOLCHAIN}" | sed 's#/#--#; s#:#---#')" \ && curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 "${LEAN_DL}/v$v/lean-$v-linux.tar.zst" -o /tmp/lean.tar.zst \ && echo "${LEAN_SHA256} /tmp/lean.tar.zst" | sha256sum -c - \ && mkdir -p "$dir" && tar --zstd -xf /tmp/lean.tar.zst -C "$dir" --strip-components 1 && rm /tmp/lean.tar.zst \ && elan default "${TOOLCHAIN}" && chmod -R a+rX /opt/elan \ && lean --version | grep -q "version $v" # --- The dependencies ------------------------------------------------------- # From the three files that name them, so that a change elsewhere in main does not fetch Mathlib's cache (5 GB) again. # Each package of the manifest is fetched at its commit first (Lake does not try a clone again when the connection # fails, and clones every package's whole history), then Mathlib's oleans: a few of the cache's downloads fail now and then, and each try fetches only what is # still missing. Mathlib's download store (~/.cache/mathlib) is unpacked into .lake by then and removed in the same # layer; so is the chmod: the cache unpacks its files 0600, and the check reads them as nobody. WORKDIR /opt/proof COPY lakefile.toml lake-manifest.json lean-toolchain /opt/proof/ RUN test "$(cat lean-toolchain)" = "${TOOLCHAIN}" \ && python3 -c 'import json; [print(p["url"], ".lake/packages/" + p["name"], p["rev"]) for p in json.load(open("lake-manifest.json"))["packages"]]' \ | while read -r url dir rev; do clone-at "$url" "$dir" "$rev" || exit 1; done \ && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ && test "$(git -C .lake/packages/batteries rev-parse HEAD)" = "${BATTERIES_COMMIT}" \ && test "$(git -C .lake/packages/aesop rev-parse HEAD)" = "${AESOP_COMMIT}" \ && (lake exe cache get || lake exe cache get || lake exe cache get) \ && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ && rm -rf /root/.cache/mathlib \ && chmod -R a+rX /opt/proof # --- Comparator and lean4export --------------------------------------------- # Each built on its own with the project's toolchain (their v4.34.0 tags ask for leanprover/lean4:v4.34.0), and # linked onto PATH. Comparator has lean4export as its package: cloned at the same commit, so Lake fetches nothing. RUN clone-at https://github.com/leanprover/lean4export /opt/lean4export "${LEAN4EXPORT_REV}" \ && echo "${TOOLCHAIN}" > /opt/lean4export/lean-toolchain \ && (cd /opt/lean4export && lake build lean4export) \ && ln -s /opt/lean4export/.lake/build/bin/lean4export /usr/local/bin/lean4export \ && chmod -R a+rX /opt/lean4export RUN clone-at https://github.com/leanprover/comparator /opt/comparator "${COMPARATOR_REV}" \ && clone-at https://github.com/leanprover/lean4export /opt/comparator/.lake/packages/lean4export "${LEAN4EXPORT_REV}" \ && echo "${TOOLCHAIN}" > /opt/comparator/lean-toolchain \ && (cd /opt/comparator && lake build comparator) \ && test "$(git -C /opt/comparator/.lake/packages/lean4export rev-parse HEAD)" = "${LEAN4EXPORT_REV}" \ && ln -s /opt/comparator/.lake/build/bin/comparator /usr/local/bin/comparator \ && chmod -R a+rX /opt/comparator # --- landrun ---------------------------------------------------------------- # The Go tarball, checksum-verified. RUN curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 "${GO_DL}/go${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tgz \ && echo "${GO_SHA256} /tmp/go.tgz" | sha256sum -c - \ && tar -C /tmp -xzf /tmp/go.tgz \ && clone-at https://github.com/Zouuup/landrun /tmp/landrun "${LANDRUN_REV}" \ && cd /tmp/landrun \ && GOPROXY="${GOPROXY}" GOTOOLCHAIN=local GOPATH=/tmp/gopath GOCACHE=/tmp/gocache /tmp/go/bin/go build -o /usr/local/bin/landrun ./cmd/landrun \ && cd / && rm -rf /tmp/go /tmp/go.tgz /tmp/landrun /tmp/gopath /tmp/gocache # --- nanoda_bin ------------------------------------------------------------- # main.json has enable_nanoda false, so Comparator does not call it; it is in the image so the second kernel can be # run on the export by hand, as upstream's ComparatorChallenges README describes. RUN export RUSTUP_HOME=/tmp/rustup CARGO_HOME=/tmp/cargo RUSTUP_DIST_SERVER="${RUST_DIST}" RUSTUP_UPDATE_ROOT="${RUST_DIST}/rustup" \ && curl -sSfL --retry 8 --retry-all-errors --connect-timeout 20 "${RUST_DIST}/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" -o /tmp/rustup-init && chmod +x /tmp/rustup-init \ && /tmp/rustup-init -y --no-modify-path --profile minimal --default-toolchain "${RUST_VERSION}" \ && if [ -n "$CARGO_MIRROR" ]; then printf '[source.crates-io]\nreplace-with = "mirror"\n[source.mirror]\nregistry = "%s"\n' "$CARGO_MIRROR" > /tmp/cargo/config.toml; fi \ && clone-at https://github.com/ammkrn/nanoda_lib /tmp/nanoda "${NANODA_REV}" \ && cd /tmp/nanoda \ && /tmp/cargo/bin/cargo build --release --locked --bin nanoda_bin \ && install -m 0755 target/release/nanoda_bin /usr/local/bin/nanoda_bin \ && cd / && rm -rf /tmp/rustup /tmp/cargo /tmp/nanoda /tmp/rustup-init # Every tool must be on PATH. RUN for t in lean4export comparator landrun nanoda_bin lake lean python3 git which; do \ command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; \ done # --- The project ------------------------------------------------------------ # The context is the tree of the project's main as git holds it (docker/build.sh sends `git archive`): it goes in # whole, as the check's commits will be, readable by all as git archives it. docker/build.sh compiles it next, in a # container. (No chmod -R here: in a layer of its own it would copy every file of Mathlib's build.) COPY . /opt/proof RUN test ! -e .git && test -d .lake/packages/mathlib \ && test -f lakefile.toml && test ! -e lakefile.lean \ && grep -q "${MATHLIB_COMMIT}" lake-manifest.json \ && grep -q "${UPSTREAM_COMMIT}" docker/lean.Dockerfile ENV PROOF_BASE=/opt/proof CMD ["/bin/bash"]