#!/bin/sh # Build the Lean image of the `build` check, on the machine whose runner will use it. # # sh docker/build.sh [] # # MIRRORS=cn take apt, Go and Rust from the mirrors a host in Beijing can reach (lean.Dockerfile's ARGs) # CPUSET=32-63 the cores the build may use (Docker's classic builder honours it; the default is all of them) # NAME=… the name of step 2's container (the default is made from the tag) # # Two steps, so that a failure late in the compile loses nothing: # 1. docker build of lean.Dockerfile: the tools, the toolchain, the dependencies with Mathlib's cache, the tree; # 2. `lake build` of the project, and of every `lean_lib` its lakefile.toml declares (the check builds them all on each # push: checks/build.py), in a container named after the tag, with no network. If it stops (a full disk, a # reboot), run this script again: the container is still there and Lake goes on from what it had built. When it # ends, the build becomes nobody's (the check then builds a commit on top of it without copying it: checks/build.py) # and the container is committed as the image. set -eu main=$(cd "$1" && pwd) tag=${2:-shoal-ym-lean:319ecd52} name=${NAME:-build-$(printf %s "$tag" | tr ':/' '--')} cpus=${CPUSET:+--cpuset-cpus $CPUSET} mirrors= if [ "${MIRRORS:-}" = cn ]; then mirrors="--build-arg APT_MIRROR=http://mirrors.aliyun.com/ubuntu --build-arg GO_DL=https://mirrors.aliyun.com/golang --build-arg GOPROXY=https://goproxy.cn,direct --build-arg RUST_DIST=https://rsproxy.cn --build-arg CARGO_MIRROR=sparse+https://rsproxy.cn/index/" fi # (the classic builder: BuildKit ignores --cpuset-cpus; the host's network: through Docker's bridge downloads crawl) DOCKER_BUILDKIT=0 docker build --network host $cpus $mirrors -f "$main/docker/lean.Dockerfile" -t "$tag-base" "$main" libs=$(python3 -I -c 'import sys, tomllib; print(*[l["name"] for l in tomllib.load(open(sys.argv[1], "rb")).get("lean_lib", [])])' "$main/lakefile.toml") docker container inspect "$name" >/dev/null 2>&1 \ || docker create --name "$name" --network none $cpus "$tag-base" bash -c \ "date +'lake build starts %T' && lake build && lake build $libs && chown -R nobody:nogroup .lake/build && chmod -R a+rX .lake/build && date +'lake build ends %T'" docker start -a "$name" docker commit -c 'CMD ["/bin/bash"]' "$name" "$tag" docker rm "$name" docker image inspect --format "$tag {{.Id}} {{.Size}} bytes" "$tag"