git clone https://garage44.eu/jeroen/midas.git.. /node/Containerfile
# A midas node: a contained checkout and build directory on a build machine,
# so that work landing on it cannot reach that machine or its network.
#
# It carries a Rust toolchain for the projects the workspace builds: rustup with
# stable and nightly, clang + lld, git and git-lfs, ALSA, Mesa with RADV and
# lavapipe (vulkan-swrast, for headless rendering on a node with no GPU), the
# wasm32, aarch64-linux-android and aarch64-unknown-none targets (and nightly's
# rust-src, for a wasm build that rebuilds std), rsync, and OpenSSH, whose sshd
# is hooked into midas. QEMU for AArch64 and x86-64, to boot a bare-metal kernel a project
# builds (pinnacle) and check what it prints, with virtio-gpu in 2D and in 3D:
# the 3D device (virglrenderer, with Venus: the guest's Vulkan run by the
# host's, lavapipe on a CPU node) needs a GL context, which `-display
# egl-headless` makes on the node's render node; a machine with no GPU gives
# it one from the kernel's vgem (`modprobe vgem`, `--gpu /dev/dri/renderD128`).
# Venus wants the PCI device (virtio-gpu-gl-pci): on MMIO, QEMU 11.1 crashes
# as soon as its host memory (`hostmem`) is asked for.
# And what `midas deploy` builds with beside cargo: bun (a web UI), trunk (a
# wasm client; it fetches the wasm-bindgen its lockfile names), a JDK 17, zip
# and the compressors (an APK and pre-compressed assets), and zig with
# cargo-zigbuild: a binary for a machine with an older glibc than this image's
# (Arch is ahead of the Ubuntu a hub usually runs) must be linked against that
# glibc, or it asks for symbols the machine does not have. And chromium, headless, to
# drive a web page a project builds. The GPU arrives as one render node at run time; an Android
# NDK, being 2 GB, is mounted read-only (`midas setup --mount`) where a machine
# has one. The midas binary is copied in from the build context: the one the
# machine's owner ran `midas setup` with.
FROM docker.io/library/archlinux:latest
RUN pacman -Syu --noconfirm --needed \
base-devel clang lld git git-lfs openssh rsync rustup \
nftables iproute2 util-linux \
mesa vulkan-radeon vulkan-swrast vulkan-icd-loader vulkan-tools \
alsa-lib pkgconf cmake python jq curl \
bun trunk jdk17-openjdk zip unzip brotli zstd zig cargo-zigbuild chromium \
qemu-system-aarch64 qemu-hw-display-virtio-gpu qemu-system-x86 qemu-system-x86-firmware \
qemu-hw-display-virtio-gpu-gl qemu-hw-display-virtio-gpu-pci qemu-hw-display-virtio-gpu-pci-gl \
qemu-ui-opengl qemu-ui-egl-headless virglrenderer \
&& pacman -Scc --noconfirm
# The one account anything that lands here runs as. uid 1000 so the files in
# the work volume map to the node owner's uid through the user namespace.
# `-p '*'`: useradd leaves the account *locked* ("!"), and sshd refuses a locked
# account even for a key login. "*" means no password can ever match, without
# the lock.
RUN useradd --create-home --uid 1000 --shell /bin/bash build \
&& usermod -p '*' build \
&& mkdir -p /work && chown build:build /work
USER build
RUN rustup toolchain install stable nightly --profile minimal \
--component rustfmt --component clippy \
&& rustup target add --toolchain nightly wasm32-unknown-unknown \
&& rustup component add --toolchain nightly rust-src \
&& rustup target add --toolchain stable aarch64-linux-android aarch64-unknown-none \
&& git lfs install
USER root
COPY midas /usr/local/bin/midas
# The owner's copy, kept: what the node's root runs (registering, taking the
# hub's build for /usr/local/bin/midas). The hub's never runs as root.
COPY midas /usr/local/libexec/midas-owner
COPY sshd_config /etc/ssh/sshd_config
COPY entrypoint.sh /usr/local/bin/midas-node-entrypoint
RUN chmod 755 /usr/local/bin/midas /usr/local/libexec/midas-owner /usr/local/bin/midas-node-entrypoint
ENTRYPOINT ["/usr/local/bin/midas-node-entrypoint"]