Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / infra / agents / Dockerfile.builder

Dockerfile.builder84 lines · 3.9 KiBRaw
1# ---------------------------------------------------------------------------
2# agents builder — the sandbox image agent code runs in.
3#
4# FROM location-share-builder:local (Ubuntu 24.04, JDK 21, Android SDK +
5# NDK 29.0.14206865 at /opt/android-sdk, Rust 1.97 in /cargo-home,
6# GRADLE_USER_HOME=/gradle-cache, /root/.cargo -> /cargo-home). On top it
7# adds the agent-runner HTTP server plus the sandbox conventions the agents
8# harness expects:
9# - unprivileged `agent` user (uid/gid 10001); the `builder` compose
10# service runs as this user,
11# - /home/agent/.cargo -> /cargo-home (build-logic/RustNative.kt invokes
12# $HOME/.cargo/bin/cargo and ignores CARGO_HOME),
13# - baked /opt/agent/gradle.properties (copied into /gradle-cache by the
14# builder-init service at first boot),
15# - ripgrep for the runner's /search route.
16#
17# Build context is infra/agents (a Cargo workspace with proto, agentd,
18# runner); only the runner is compiled in. The `location-share-builder:local`
19# base must exist first (built from /root/location_share_server), so this
20# image is built with `docker compose -p agents -f infra/agents/compose.yml
21# build` on the host, never here.
22#
23# NOTE: the base image declares VOLUME ["/gradle-cache","/cargo-home",
24# "/opt/android-sdk"]. A VOLUME path cannot be chowned in later RUN layers
25# and becomes an anonymous volume if not mounted, so compose mounts all
26# three explicitly (bind-backed named volumes seeded from the image).
27# ---------------------------------------------------------------------------
28
29# ---- stage 1: compile agent-runner ---------------------------------------
30FROM rust:1-bookworm AS runner-build
31WORKDIR /src
32# Workspace layout: Cargo.toml + the three member crates. Copying only these
33# keeps the build cache stable when unrelated tree files change.
34COPY Cargo.toml Cargo.lock ./
35COPY proto ./proto
36COPY runner ./runner
37# agentd has its own Dockerfile; only its manifest is needed here (plus an
38# empty main) so the workspace resolves without compiling it.
39COPY agentd/Cargo.toml ./agentd/Cargo.toml
40RUN mkdir -p agentd/src && echo 'fn main() {}' > agentd/src/main.rs
41RUN cargo build -p agent-runner --release --locked
42
43# ---- stage 2: sandbox -------------------------------------------------------
44FROM location-share-builder:local
45
46ENV ANDROID_HOME=/opt/android-sdk \
47 ANDROID_SDK_ROOT=/opt/android-sdk
48
49RUN apt-get update && apt-get install -y --no-install-recommends \
50 ripgrep \
51 tini \
52 && rm -rf /var/lib/apt/lists/*
53
54# Unprivileged sandbox user. The compose file runs the builder service as
55# 10001:10001 and bind-mounts the caches; /home/agent/.cargo mirrors the
56# base image's /root/.cargo symlink so Gradle's RustNative.kt finds cargo.
57RUN groupadd -g 10001 agent \
58 && useradd -m -u 10001 -g 10001 -d /home/agent -s /bin/bash agent \
59 && ln -sfn /cargo-home /home/agent/.cargo
60
61COPY --from=runner-build /src/target/release/agent-runner /usr/local/bin/agent-runner
62
63# The mirror is owned by agentd's uid; git 2.43 only honours safe.directory
64# from system/global config (not `-c`), so trust it here or every clone fails
65# with "dubious ownership".
66RUN git config --system --add safe.directory /mirror/Modern-Apps.git
67
68# Stand-in for no-new-privileges (unusable under snap Docker, see compose.yml):
69# with no setuid/setgid binaries, the uid-10001 sandbox has no path to root.
70RUN find / -xdev -type f -perm /6000 -exec chmod a-s {} + 2>/dev/null || true
71
72# Gradle memory/concurrency profile for the 6-CPU / 14 GB sandbox (smaller
73# than release builds: 4 workers / 12 GB). builder-init copies this into
74# /gradle-cache/gradle.properties on first boot; a repo-level
75# gradle.properties is left untouched.
76COPY gradle.properties /opt/agent/gradle.properties
77
78WORKDIR /builds/slots
79
80# Undo the base image's release ENTRYPOINT: this container serves the runner
81# API instead. tini reaps stray grandchildren so killpg'd builds don't leak
82# zombies into pid 1.
83ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/agent-runner"]
84CMD []