#!/bin/sh # Builds the Lean image of poincare-conjecture in three steps, so the hours-long compile is never a Dockerfile # layer that a failure throws away: # # sh docker/build.sh base the image shoal-poincare-lean:62db01af-base (lean.Dockerfile: minutes) # sh docker/build.sh start the long step, detached, in the container $NAME on top of the base (hours) # sh docker/build.sh commit once the container has exited 0: the image shoal-poincare-lean:62db01af # # Watch the long step with `docker logs --tail 3 $NAME`. If it stops (a kill, a reboot, a full disk), `docker start # $NAME` goes on from the modules already compiled. Settings, all optional: CPUSET (the cores to use, as docker's # --cpuset-cpus, e.g. 64-95), MEMORY (default 256g), NAME (default poincare-lean-build). set -eu TAG=shoal-poincare-lean:62db01af NAME=${NAME:-poincare-lean-build} CPUSET=${CPUSET:-} MEMORY=${MEMORY:-256g} here=$(cd "$(dirname "$0")" && pwd) # What the long step runs. The default targets (PoincareConjecture, PoincareLib), then the Comparator modules and # the two tools as the project's Comparator/README.md says; the tools go on PATH; all of /opt is opened to `nobody`, # the user the check runs a commit's Lean as, and the project's own build is given to `nobody`: the check compiles a # commit on top of it, inside the job's container, and writes only what the commit changed (scripts/lean-ci/README.md; # the dependencies' builds under .lake/packages stay root's). Lake writes a setup.json before it compiles a module # (every transitive import's path, 1.5 MB here) and never reads it again: 35 GB of a 51 GB build, deleted. It needs no # network: the base fetched everything. LONG='set -eu cd /opt/proof lake build lake build Challenge Solution @Comparator/comparator @lean4export/lean4export ln -sf /opt/proof/.lake/packages/Comparator/.lake/build/bin/comparator /usr/local/bin/comparator ln -sf /opt/proof/.lake/packages/lean4export/.lake/build/bin/lean4export /usr/local/bin/lean4export for t in lean4export comparator landrun nanoda_bin lake lean; do command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; done find /opt/proof/.lake/build -name "*.setup.json" -delete chmod -R a+rX /opt chown -R nobody:nogroup /opt/proof/.lake/build echo "long step done"' case "${1:-}" in base) DOCKER_BUILDKIT=0 docker build --network host ${CPUSET:+--cpuset-cpus "$CPUSET"} \ -f "$here/lean.Dockerfile" -t "$TAG-base" "$here" ;; start) docker run -d --name "$NAME" --network none ${CPUSET:+--cpuset-cpus "$CPUSET"} --memory "$MEMORY" \ "$TAG-base" sh -c "$LONG" ;; commit) test "$(docker inspect -f '{{.State.Status}} {{.State.ExitCode}}' "$NAME")" = "exited 0" \ || { echo "$NAME has not finished cleanly; see docker logs --tail 20 $NAME, then docker start $NAME"; exit 1; } docker commit --change 'ENV PROOF_BASE=/opt/proof' --change 'WORKDIR /opt/proof' --change 'CMD ["/bin/bash"]' \ "$NAME" "$TAG" docker rm "$NAME" ;; *) echo "usage: sh docker/build.sh base|start|commit"; exit 2 ;; esac