Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
235 lines (201 loc) · 9.44 KB
/
Copy pathDockerfile
File metadata and controls
235 lines (201 loc) · 9.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# syntax=docker/dockerfile:1.7-labs
###############################################################################
# oh-my-pi — pi image
#
# Stages:
# natives-builder — Rust + Bun → pi_natives.linux-<arch>.node
# wheel-builder — omp_rpc Python wheel
# pi-base — python + bun + rustup launcher + natives + omp_rpc
# + /usr/local/bin/omp shim
# pi-runtime — pi-base + pi source + bun install (DEFAULT, runnable)
#
# Build:
# docker build -t oh-my-pi/pi:dev . # default = pi-runtime
# docker build --target pi-base -t oh-my-pi/pi-base:dev . # base for derived images
#
# Run:
# docker run --rm oh-my-pi/pi:dev --help
# docker run --rm -it -v "$PWD":/work oh-my-pi/pi:dev cli # interactive omp
#
# Consume as a base in another Dockerfile (see Dockerfile.robomp):
# ARG PI_BASE=oh-my-pi/pi:dev
# FROM ${PI_BASE} AS pi-base
###############################################################################
ARG BUN_VERSION=1.4.4
############################
# 1) natives-builder — Rust + Bun → pi_natives.linux-<arch>.node (local cargo)
############################
FROM rust:1.86-slim-bookworm AS natives-builder
ARG BUN_VERSION
# The addon is built with the default cargo/napi-rs host backend, not Bazel:
# the image is one fixed host target, so Bazel's hermetic cross toolchains
# and crate_universe splice buy nothing while costing a bazelisk download
# plus a full analysis phase on every build. `ci` profile = release codegen,
# thin LTO, stripped.
ENV BUN_INSTALL=/opt/bun \
PATH=/opt/bun/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/bin:/bin \
CARGO_TERM_COLOR=never \
OMP_NATIVE_CARGO_PROFILE=ci
# clang/libclang-dev: bindgen for pipewire-sys/libspa-sys (Linux desktop capture);
# cmake/make/ninja-build: opusic-sys builds bundled libopus via CMake.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl ca-certificates pkg-config libssl-dev unzip git \
clang libclang-dev cmake make ninja-build \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}" \
&& /opt/bun/bin/bun --version
WORKDIR /pi
# Layer 0 — the pinned nightly toolchain. Its own layer so a source or manifest
# edit never re-downloads ~5 rustup components.
COPY rust-toolchain.toml /pi/
RUN rustup show
# Layer 1 — manifests + lockfiles only. Source edits under packages/*/src and
# crates/*/src won't bust `bun install` below. `--parents` preserves the
# matched path under /pi/ (requires syntax 1.7-labs).
COPY --parents \
package.json bun.lock bunfig.toml \
patches/*.patch \
tsconfig.base.json tsconfig.json \
Cargo.toml Cargo.lock rust-toolchain.toml \
packages/*/package.json \
packages/tsconfig.workspace.json \
python/robomp/web/package.json \
crates/*/Cargo.toml \
/pi/
# Layer 2 — hydrate node_modules from the manifests above.
RUN bun install --frozen-lockfile --ignore-scripts
# Layer 3 — full source. `Dockerfile.dockerignore` keeps target/, node_modules/,
# dist/, runs/, editor noise, etc. out of the context. node_modules from Layer 2
# is preserved across this COPY because it's never in the build context.
COPY . /pi/
# Hash the exact input trees in the build context before generated files change.
# Extra untracked inputs change the key and safely result in a cache miss.
RUN set -eux; \
git init --bare /tmp/native-key.git; \
export GIT_DIR=/tmp/native-key.git GIT_WORK_TREE=/pi; \
git add -f -- crates Cargo.lock Cargo.toml rust-toolchain.toml packages/natives \
':(exclude)**/node_modules/**' ':(exclude)packages/natives/native/.build/**'; \
tree="$(git write-tree)"; \
mkdir -p /out/natives-seed; \
printf '%s\n' "$tree:crates" "$tree:Cargo.lock" "$tree:Cargo.toml" \
"$tree:rust-toolchain.toml" "$tree:packages/natives" \
| git cat-file --batch-check > /out/natives-seed/trees.txt; \
rm -rf /tmp/native-key.git
# Layer 4 — compile pi-natives to a Linux N-API addon. Persistent caches keep
# repeat builds incremental: cargo's package index + git-deps (CARGO_HOME is
# /usr/local/cargo in the rust image, not ~/.cargo) + the workspace target dir.
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/pi/target \
set -eux; \
bun --cwd=packages/natives run build; \
mkdir -p /out; \
cp packages/natives/native/pi_natives.linux-*.node /out/; \
cp packages/natives/native/pi_natives.linux-*.node \
packages/natives/native/index.d.ts packages/natives/native/index.js \
packages/natives/native/embedded-addon.js /out/natives-seed/
############################
# 2) wheel-builder — omp-rpc wheel
############################
FROM python:3.12-slim-bookworm AS wheel-builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip build
WORKDIR /src
COPY sdk/python/omp-rpc /src
RUN python -m build --wheel --outdir /out
############################
# 3) pi-base — python + bun + rustup + natives + omp_rpc + omp shim
#
# Sharable runtime base. Derived images (pi-runtime below, Dockerfile.robomp)
# extend this and overlay their own source tree. Default PI_ROOT=/work/pi is
# friendly to derived images that mount a host pi checkout there; pi-runtime
# overrides it to /pi because its source is baked in.
############################
FROM python:3.12-slim-bookworm AS pi-base
ARG BUN_VERSION
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
BUN_INSTALL=/opt/bun \
PI_ROOT=/work/pi \
CARGO_HOME=/data/cache/cargo \
CARGO_TARGET_DIR=/data/cache/cargo-target \
RUSTUP_HOME=/data/cache/rustup \
PATH=/opt/bun/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/bun-node-fallback-bin
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git curl ca-certificates unzip openssh-client tini sqlite3 \
build-essential pkg-config libssl-dev \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://bun.sh/install | bash -s "bun-v${BUN_VERSION}" \
&& /opt/bun/bin/bun --version
# `node` → bun, last on PATH (same layout as the oven/bun images) so
# `#!/usr/bin/env node` package bins (oxlint, oxfmt, …) run for every uid.
# Bun's own fallback is a /tmp/bun-node-<hash> dir created 0700 by the first
# user that needs it; the image build runs as root, so it would bake a dir
# no robomp slot user can enter.
RUN mkdir -p /usr/local/bun-node-fallback-bin \
&& ln -s /opt/bun/bin/bun /usr/local/bun-node-fallback-bin/node
# Rustup launcher only — the real toolchain is fetched lazily into RUSTUP_HOME
# on first cargo invocation, driven by pi's `rust-toolchain.toml`. Keeps the
# image small while sharing the toolchain across reboots when /data is mounted.
RUN curl -fsSL https://sh.rustup.rs -o /tmp/rustup-init.sh \
&& CARGO_HOME=/usr/local/cargo RUSTUP_HOME=/usr/local/rustup-bootstrap \
sh /tmp/rustup-init.sh -y --no-modify-path --default-toolchain none --profile minimal \
&& rm -f /tmp/rustup-init.sh \
&& rm -rf /usr/local/rustup-bootstrap \
&& /usr/local/cargo/bin/rustup --version
# pi-natives addon: pi's loader probes /opt/bun/bin as a fallback path.
COPY --from=natives-builder /out/pi_natives.linux-*.node /opt/bun/bin/
COPY --from=natives-builder /out/natives-seed/ /opt/pi-natives-seed/
# omp-rpc Python wheel.
COPY --from=wheel-builder /out/*.whl /tmp/wheels/
RUN pip install /tmp/wheels/omp_rpc-*.whl && rm -rf /tmp/wheels
# Legal payload for the OMP license and the native addon installed above.
COPY LICENSE packages/natives/THIRD-PARTY-NOTICES.txt /usr/share/doc/omp/
# `omp` shim — runs the coding-agent CLI against $PI_ROOT via Bun. Derived
# images override PI_ROOT to point at wherever their pi source lives.
RUN printf '%s\n' \
'#!/usr/bin/env bash' \
'set -euo pipefail' \
': "${PI_ROOT:=/work/pi}"' \
'if [ ! -d "$PI_ROOT/packages/coding-agent" ]; then' \
' echo "pi: PI_ROOT=$PI_ROOT does not look like a pi checkout" >&2' \
' exit 127' \
'fi' \
'exec bun "$PI_ROOT/packages/coding-agent/src/cli.ts" "$@"' \
> /usr/local/bin/omp \
&& chmod +x /usr/local/bin/omp
############################
# 4) pi-runtime — pi-base + pi source + bun install (DEFAULT)
#
# A self-contained, runnable omp image. `docker run oh-my-pi/pi:dev --help`
# Just Works without a host checkout.
############################
FROM pi-base AS pi-runtime
ENV PI_ROOT=/pi
WORKDIR /pi
# Same manifests-only layered install pattern as natives-builder — `bun install`
# only re-runs when a package.json / lockfile changes.
COPY --parents \
package.json bun.lock bunfig.toml \
patches/*.patch \
tsconfig.base.json tsconfig.json \
packages/*/package.json \
packages/tsconfig.workspace.json \
python/robomp/web/package.json \
/pi/
RUN bun install --frozen-lockfile --ignore-scripts
# Pi source. `Dockerfile.dockerignore` keeps **/node_modules out of the context
# so stale isolated-linker symlinks from a host install can't shadow the
# hoisted node_modules that `bun install` just produced.
COPY . /pi/
# Generate the hosted viewer metadata that `--ignore-scripts` skipped above.
# The root prepare script normally handles it on a vanilla install.
RUN bun --cwd=packages/coding-agent run gen:export-viewer
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/omp"]
CMD ["--help"]