Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Harness OS: build the Orange Pi 4 Pro image in Docker

bubu-dudue2cca56aa51d
diff --git a/os/platforms/orangepi-4pro/README.md b/os/platforms/orangepi-4pro/README.md
index f8492b555..1dc383b0c 100644
--- a/os/platforms/orangepi-4pro/README.md
+++ b/os/platforms/orangepi-4pro/README.md
@@ -26,7 +26,19 @@ installer, system updates, PC drivers and boot splash.
## Build
-On the board, running Orange Pi's Debian 12 server image, with a clean checkout:
+With Docker, on any host:
+
+```sh
+bash os/platforms/orangepi-4pro/build-docker.sh \
+ Orangepi4pro_1.0.6_debian_bookworm_server_linux5.15.147.img out/
+```
+
+It runs the three steps below in a privileged arm64 Debian 12 container from the committed
+HEAD, and writes `harness-orangepi4pro-debian12-<commit>.img.xz` with its `.sha256`. Named
+volumes keep cargo downloads and the compositor build between runs. An x86-64 host emulates
+arm64 with QEMU, so a first build there takes hours; an arm64 host builds natively.
+
+Or natively on the board, running Orange Pi's Debian 12 server image, with a clean checkout:
```sh
sudo apt install build-essential musl-tools cmake ninja-build pkg-config python3-venv parted \
diff --git a/os/platforms/orangepi-4pro/build-docker.sh b/os/platforms/orangepi-4pro/build-docker.sh
new file mode 100755
index 000000000..c79fe8643
--- /dev/null
+++ b/os/platforms/orangepi-4pro/build-docker.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# Build the Orange Pi 4 Pro image in an arm64 Debian 12 container instead of on the board.
+# Runs build-runtime.sh, build-compositor.sh and build-image.sh unchanged inside it.
+# An x86-64 host emulates arm64 through Docker's QEMU (slow: a first build takes hours);
+# an arm64 host (Apple Silicon, an arm64 Linux runner) builds natively.
+# Usage: build-docker.sh BASE.img OUTPUT_DIR
+# BASE.img Orange Pi's official Orangepi4pro_*_debian_bookworm_server_*.img (checked
+# against its .sha first)
+# OUTPUT_DIR receives harness-orangepi4pro-debian12-<commit>.img.xz and its .sha256
+# The build uses the committed HEAD of this checkout; uncommitted changes are not included.
+set -euo pipefail
+BASE=$(cd -- "$(dirname -- "${1:?base image}")" && pwd)/$(basename -- "$1")
+OUT=$(mkdir -p -- "${2:?output directory}" && cd -- "$2" && pwd)
+SOURCE=$(cd -- "$(dirname -- "$0")/../../.." && pwd)
+BUILDER=harness-orangepi4pro-builder
+[[ -f $BASE ]] || { echo "No base image at $BASE" >&2; exit 1; }
+if [[ -n $(git -C "$SOURCE" status --porcelain --untracked-files=no) ]]; then
+ echo 'Uncommitted changes are not part of the build; it uses HEAD.' >&2
+fi
+
+docker build --platform linux/arm64 -t "$BUILDER" - <<'EOF'
+FROM debian:bookworm
+ENV DEBIAN_FRONTEND=noninteractive LC_ALL=C.UTF-8 \
+ RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:$PATH
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ ca-certificates curl git jq xz-utils python3 python3-venv build-essential musl-tools \
+ cmake ninja-build pkg-config parted e2fsprogs fdisk udev \
+ libffi-dev libexpat1-dev libxml2-dev libudev-dev libmtdev-dev libevdev-dev libseat-dev \
+ libegl-dev libgles-dev libgbm-dev hwdata libglib2.0-dev libcairo2-dev libpango1.0-dev \
+ libpng-dev librsvg2-dev libpciaccess-dev \
+ && curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
+ && apt-get install -y --no-install-recommends nodejs \
+ && rm -rf /var/lib/apt/lists/*
+RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal \
+ && rustup target add aarch64-unknown-linux-musl
+EOF
+
+# Named volumes keep the slow parts between builds: cargo downloads, the compositor's
+# sources and done-markers, and its install prefix (whose path the image keeps).
+docker run --rm --privileged --platform linux/arm64 \
+ -v "$SOURCE":/src:ro -v "$BASE":/base.img:ro -v "$OUT":/out \
+ -v harness-orangepi4pro-cargo:/usr/local/cargo/registry \
+ -v harness-orangepi4pro-wl-work:/cache/wl \
+ -v harness-orangepi4pro-wl:/opt/harness-wl \
+ -e HARNESS_WL_WORK=/cache/wl \
+ "$BUILDER" bash -euo pipefail -c '
+git config --global --add safe.directory /src
+git clone -q /src /build
+cd /build
+COMMIT=$(git rev-parse --short HEAD)
+HARNESS_OS_RUNTIME_DIR=/build/os/work/runtime-arm bash os/tools/build-runtime.sh
+bash os/platforms/orangepi-4pro/build-compositor.sh
+IMG=/build/harness-orangepi4pro-debian12-$COMMIT.img
+bash os/platforms/orangepi-4pro/build-image.sh /base.img /build/os/work/runtime-arm "$IMG"
+xz -T0 -6 -c "$IMG" > "/out/${IMG##*/}.xz"
+cd /out && sha256sum "${IMG##*/}.xz" > "${IMG##*/}.xz.sha256"
+ls -la /out
+'
diff --git a/os/platforms/orangepi-4pro/build-image.sh b/os/platforms/orangepi-4pro/build-image.sh
index e82497c39..8497b32d1 100755
--- a/os/platforms/orangepi-4pro/build-image.sh
+++ b/os/platforms/orangepi-4pro/build-image.sh
@@ -23,18 +23,27 @@ cleanup() {
for m in dev/pts dev proc sys; do mountpoint -q "$MNT/$m" && umount "$MNT/$m"; done
mountpoint -q "$MNT" && umount "$MNT"
[[ -n $LOOP ]] && losetup -d "$LOOP"
+ [[ -n $MADE_NODE ]] && rm -f "$MADE_NODE"
rmdir "$MNT"
}
+MADE_NODE=
trap cleanup EXIT
cp --sparse=always "$BASE" "$OUT"
truncate -s +3G "$OUT"
LOOP=$(losetup -fP --show "$OUT")
parted -s "$LOOP" resizepart 1 100%
-partprobe "$LOOP"
-e2fsck -fy "${LOOP}p1" >/dev/null || true
-resize2fs "${LOOP}p1" >/dev/null
-mount "${LOOP}p1" "$MNT"
+partprobe "$LOOP" || true
+PART=${LOOP}p1
+if [[ ! -b $PART ]]; then
+ # A container (build-docker.sh) has no udev to create partition nodes.
+ IFS=: read -r major minor < "/sys/class/block/${LOOP#/dev/}p1/dev"
+ mknod "$PART" b "$major" "$minor"
+ MADE_NODE=$PART
+fi
+e2fsck -fy "$PART" >/dev/null || true
+resize2fs "$PART" >/dev/null
+mount "$PART" "$MNT"
for m in dev dev/pts proc sys; do mount --bind "/$m" "$MNT/$m"; done
# Network for the chroot; the image's own resolv.conf is restored afterwards.
mv "$MNT/etc/resolv.conf" "$MNT/etc/resolv.conf.harness" 2>/dev/null || true