# Base of the Lean image for the poincare-conjecture `build` check (checks/build.py): everything except the # compile of the project itself. # # Do not build this file by hand: `sh docker/build.sh` builds it as shoal-poincare-lean:62db01af-base, runs the # hours-long `lake build` in a named container on top of it (so a failure resumes with `docker start` instead of # starting over), and commits that container as shoal-poincare-lean:62db01af. See README.md. # # The base holds the toolchain, the upstream proof at its pinned commit in /opt/proof with Mathlib's oleans from its # cache, and Comparator's two outside tools (landrun, nanoda_bin). The project is 23,554 Lean files (3.06 million # lines); compiling them is the long step. # # Every pin is a full commit hash in an ARG below, and each clone is checked against it. Downloads are written for # a host in mainland China (raw.githubusercontent.com is closed there, go.dev and crates.io are slow); the mirrors # are ARGs, so elsewhere pass the official addresses with --build-arg. FROM ubuntu:24.04 # --- Pins ------------------------------------------------------------------- # frenzymath/PoincareConjecture, and its lean-toolchain at that commit. ARG UPSTREAM_REPO=https://github.com/frenzymath/PoincareConjecture ARG UPSTREAM_COMMIT=62db01af9388dc1d9b56b66d6674f4c09b2318a2 ARG TOOLCHAIN=leanprover/lean4:v4.33.1 # From the upstream lakefile.toml / lake-manifest.json; checked after the dependencies are fetched. Comparator and # lean4export are Lake packages of the project, so the long step builds them. ARG MATHLIB_COMMIT=0df444a360eaa60ab8c11dca51a86af692955474 ARG COMPARATOR_REV=3927ad383f208ae977c340a91c48ac9b497d2097 ARG LEAN4EXPORT_REV=15f6055e299ad5b89345e533cc2192f4cc00f659 # Sandbox and second kernel, as pinned in this project's Comparator/README.md. ARG LANDRUN_REV=811cfff51ceaf3d9843708aa6d22e9b84ccac8b4 # ^ landrun 0.1.18 ARG NANODA_REV=079049d584b2aed2b0172218164082f4fc6eede2 # ^ nanoda_lib 0.4.18 # Build tools for landrun (go.mod asks for Go 1.24) and nanoda (Rust), and where to get them. ARG ELAN_URL=https://github.com/leanprover/elan/releases/download/v4.1.2/elan-x86_64-unknown-linux-gnu.tar.gz ARG GO_VERSION=1.24.13 ARG GO_SHA256=1fc94b57134d51669c72173ad5d49fd62afb0f1db9bf3f798fd98ee423f8d730 ARG GO_DIST=https://mirrors.aliyun.com/golang ARG GOPROXY=https://goproxy.cn,direct ARG RUST_VERSION=1.100.1 ARG RUST_DIST=https://rsproxy.cn ARG CRATES_INDEX=sparse+https://rsproxy.cn/index/ ARG APT_MIRROR=http://mirrors.aliyun.com/ubuntu # --- System packages -------------------------------------------------------- # python3, curl and zstd are what Lake and Mathlib's cache tool use. ENV DEBIAN_FRONTEND=noninteractive RUN sed -i "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g; s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \ /etc/apt/sources.list.d/ubuntu.sources \ && 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 Lean as `nobody`; let git (and Lake, which calls git in each package) read every # repository in the image. RUN git config --system --add safe.directory '*' # --- Lean ------------------------------------------------------------------- # elan from its GitHub release (the install script lives on raw.githubusercontent.com). ENV ELAN_HOME=/opt/elan ENV PATH=/usr/local/bin:/opt/elan/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin RUN curl -sSfL --retry 5 "${ELAN_URL}" | tar -xz -C /tmp \ && /tmp/elan-init -y --no-modify-path --default-toolchain none \ && rm /tmp/elan-init \ && elan toolchain install "${TOOLCHAIN}" \ && elan default "${TOOLCHAIN}" \ && chmod -R a+rX /opt/elan # --- The proof -------------------------------------------------------------- # The clone sometimes breaks off in TLS: up to five tries. RUN for i in 1 2 3 4 5; do \ rm -rf /opt/proof; git clone "${UPSTREAM_REPO}" /opt/proof && break; sleep 10; \ done \ && git -C /opt/proof checkout "${UPSTREAM_COMMIT}" \ && test "$(git -C /opt/proof rev-parse HEAD)" = "${UPSTREAM_COMMIT}" \ && test "$(cat /opt/proof/lean-toolchain)" = "${TOOLCHAIN}" WORKDIR /opt/proof # Mathlib's oleans (the cache tool loses a few downloads on a bad line: up to three runs, then Lake itself must # find nothing of Mathlib left to compile), then every dependency at the manifest's commit. Mathlib's download # store (~/.cache/mathlib) is unpacked into .lake by then and removed in the same layer; the cache unpacks its # files 0600, so they are opened to `nobody` here too. RUN for i in 1 2 3; do lake exe cache get && break; sleep 10; done \ && lake build --no-build Mathlib \ && test "$(git -C .lake/packages/mathlib rev-parse HEAD)" = "${MATHLIB_COMMIT}" \ && test "$(git -C .lake/packages/Comparator rev-parse HEAD)" = "${COMPARATOR_REV}" \ && test "$(git -C .lake/packages/lean4export rev-parse HEAD)" = "${LEAN4EXPORT_REV}" \ && git diff --quiet -- lake-manifest.json \ && rm -rf /root/.cache/mathlib \ && chmod -R a+rX /opt/proof # --- landrun ---------------------------------------------------------------- # Go tarball, checksum-verified, used only for this build and removed. RUN curl -sSfL --retry 5 "${GO_DIST}/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 \ && for i in 1 2 3 4 5; do \ rm -rf /tmp/landrun; git clone https://github.com/Zouuup/landrun /tmp/landrun && break; sleep 10; \ done \ && git -C /tmp/landrun checkout "${LANDRUN_REV}" \ && test "$(git -C /tmp/landrun rev-parse HEAD)" = "${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 \ && chmod -R u+w /tmp/gopath \ && rm -rf /tmp/go /tmp/go.tgz /tmp/landrun /tmp/gopath /tmp/gocache # --- nanoda_bin ------------------------------------------------------------- # rustup with a pinned Rust in /tmp, used only for this build and removed. RUN export RUSTUP_HOME=/tmp/rustup CARGO_HOME=/tmp/cargo \ RUSTUP_DIST_SERVER="${RUST_DIST}" RUSTUP_UPDATE_ROOT="${RUST_DIST}/rustup" \ && mkdir -p /tmp/cargo \ && printf '[source.crates-io]\nreplace-with = "mirror"\n[source.mirror]\nregistry = "%s"\n' "${CRATES_INDEX}" \ > /tmp/cargo/config.toml \ && curl -sSfL --retry 5 "${RUST_DIST}/rustup-init.sh" \ | sh -s -- -y --no-modify-path --profile minimal --default-toolchain "${RUST_VERSION}" \ && for i in 1 2 3 4 5; do \ rm -rf /tmp/nanoda; git clone https://github.com/ammkrn/nanoda_lib /tmp/nanoda && break; sleep 10; \ done \ && git -C /tmp/nanoda checkout "${NANODA_REV}" \ && test "$(git -C /tmp/nanoda rev-parse HEAD)" = "${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 \ && rm -rf /tmp/rustup /tmp/cargo /tmp/nanoda # The tools of the project (comparator, lean4export) are built by the long step, which links them here. ENV PROOF_BASE=/opt/proof WORKDIR /opt/proof CMD ["/bin/bash"]