# Lean image for the navier-stokes `build` check (checks/build.py): everything before the long step. # # docker/build.sh builds this file with a checkout of the project's main as the context, then compiles the project in # a container of the result and commits that container as the image the check uses (docker/README.md). The compile is # 2,646 files; as a layer, one failure late in it would lose all of it. # # The project's main is openai/NavierStokesAndEuler at f9e8bc5b38b6e212696e8a30e3e91517af887bbd (upstream.json) with # this project's own files on top. # # The check runs with --network none: it reads the commit's tree, uses /opt/proof/.lake (the dependencies, and the # build of the approved main) and runs lake build, lean4export and Comparator. Nothing is downloaded at check time. # # Every pin is a full commit hash in an ARG below, checked once it is fetched. 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), Go from Aliyun, Go modules from # goproxy.cn, Rust and its crates from rsproxy.cn. raw.githubusercontent.com is not used: Beijing cannot reach it. ARG APT_MIRROR= 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= # --- Pins ------------------------------------------------------------------- # The project's lean-toolchain, and from its lake-manifest.json (the lakefile asks for tag v4.34.0-rc2 of each). # Comparator and lean4export are Lake packages of the project, so Lake fetches and builds them. ARG TOOLCHAIN=leanprover/lean4:v4.34.0-rc2 ARG MATHLIB_COMMIT=85e3a25e006c35636f0e53b0e9296caca2685bc0 ARG COMPARATOR_REV=19e111e2141cf333c7daff0f64c5f24acc91dd2e ARG LEAN4EXPORT_REV=cacf989bd75f608700820f6afc595f32e7a99a4d # Comparator's sandbox and its second kernel, as pinned in PoincareConjecture'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), 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 Lake as another user than the one that built; let git (Lake asks it about each package) read every # repository in the image. RUN git config --system --add safe.directory '*' # --- landrun ---------------------------------------------------------------- # (a clone from github.com sometimes breaks off in TLS from Beijing: each is tried five times) RUN curl -sSfL --retry 5 "${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 \ && for i in 1 2 3 4 5; do git clone https://github.com/Zouuup/landrun /tmp/landrun && break; rm -rf /tmp/landrun; 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 \ && cd / && rm -rf /tmp/go /tmp/go.tgz /tmp/landrun /tmp/gopath /tmp/gocache # --- nanoda_bin ------------------------------------------------------------- RUN export RUSTUP_HOME=/tmp/rustup CARGO_HOME=/tmp/cargo RUSTUP_DIST_SERVER="${RUST_DIST}" RUSTUP_UPDATE_ROOT="${RUST_DIST}/rustup" \ && curl -sSfL --retry 5 "${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 \ && for i in 1 2 3 4 5; do git clone https://github.com/ammkrn/nanoda_lib /tmp/nanoda && break; rm -rf /tmp/nanoda; 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 \ && cd / && rm -rf /tmp/rustup /tmp/cargo /tmp/nanoda /tmp/rustup-init # --- Lean ------------------------------------------------------------------- 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 https://github.com/leanprover/elan/releases/download/v4.1.2/elan-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C /tmp \ && /tmp/elan-init -y --no-modify-path --default-toolchain none && rm /tmp/elan-init RUN elan toolchain install "${TOOLCHAIN}" \ && elan default "${TOOLCHAIN}" # --- 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 as the one commit it is pinned at, where Lake would clone it with its # history: Mathlib's is about a gigabyte, and from Beijing github.com gave 0.6 MB/s and one connection in a few hung # for two minutes (12-02). Lake finds each at its rev and fetches nothing. Then Mathlib's cache, up to six times: a few # of its downloads fail now and then, and each try fetches what is still missing. # chmod in this same layer: Mathlib's cache unpacks its files 0600, and the check compiles the commit as nobody (in a # later layer the chmod would copy every file). WORKDIR /opt/proof COPY lakefile.toml lake-manifest.json lean-toolchain /opt/proof/ RUN test "$(cat lean-toolchain)" = "${TOOLCHAIN}" \ && python3 -I -c 'import json; [print(p["url"], p["name"], p["rev"]) for p in json.load(open("lake-manifest.json"))["packages"]]' > /tmp/packages \ && while read -r url name rev; do \ for i in 1 2 3 4 5 6 7 8; do \ rm -rf ".lake/packages/$name" && git init -q ".lake/packages/$name" && git -C ".lake/packages/$name" remote add origin "$url" \ && timeout 900 git -C ".lake/packages/$name" fetch -q --depth 1 origin "$rev" \ && git -C ".lake/packages/$name" checkout -q --detach FETCH_HEAD && break; \ sleep 5; \ done; \ test "$(git -C ".lake/packages/$name" rev-parse HEAD)" = "$rev" || { echo "not fetched: $name at $rev"; exit 1; }; \ done < /tmp/packages && rm /tmp/packages \ && (for i in 1 2 3 4 5 6; do lake exe cache get && exit 0; sleep 10; done; exit 1) \ && 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}" \ && rm -rf /root/.cache/mathlib \ && chmod -R a+rX /opt/proof /opt/elan # Comparator and lean4export are packages of the project: its Lake builds them. RUN lake build @Comparator/comparator @lean4export/lean4export # Comparator looks lean4export, landrun and nanoda_bin up on PATH; the check starts `comparator` and `lean4export` # by name too. RUN ln -s /opt/proof/.lake/packages/Comparator/.lake/build/bin/comparator /usr/local/bin/comparator \ && ln -s /opt/proof/.lake/packages/lean4export/.lake/build/bin/lean4export /usr/local/bin/lean4export \ && for t in lean4export comparator landrun nanoda_bin lake lean python3; do \ command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; \ done # --- The project ------------------------------------------------------------ # The context is a checkout of the project's main: its tree goes in whole, as the check's commits will be. # docker/build.sh compiles it next, in a container. # (no chmod -R here: in a later layer it copies every file it visits, Mathlib's 7 GB included, changed or not; # a checkout's files are readable as they come) COPY . /opt/proof RUN rm -rf .git ENV PROOF_BASE=/opt/proof CMD ["/bin/bash"]