Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ FROM python:3.12-slim AS preview-wheel-builder

WORKDIR /build
COPY artemis/ ./artemis/
COPY device_lease/ ./device_lease/
COPY apps/ ./apps/
COPY mcp_server/ ./mcp_server/
COPY third_party/ ./third_party/
Expand Down
47 changes: 37 additions & 10 deletions docs/preview-build.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Offline preview build: Node and Python inputs

The preview controller separates networked acquisition from offline hook
execution. This stage delivers the showcase UI build, not a runnable preview:
`--target preview` keeps its non-root user (UID/GID 10001),
`ARTEMIS_PREVIEW_PROFILE=1` and Uvicorn command. It installs the Python app
and its locked dependencies from a hash-locked wheelhouse (see "Python
inputs"), but no system libraries yet. Do not activate this target until
the app-start proof lands. The live console remains the
default target and its Dockerfile stages are unchanged.
execution. `--target preview` keeps its non-root user (UID/GID 10001),
`ARTEMIS_PREVIEW_PROFILE=1` and Uvicorn command. It builds the showcase UI,
and installs the Python app and its locked dependencies from a hash-locked
wheelhouse (see "Python inputs"), with no network in any `RUN`. It adds no
system libraries: OpenCV comes from `opencv-python-headless`, which needs
none. The app-start proof passed on X99 (see "App-start proof"), so the
target is usable. The live console remains the default target and its
Dockerfile stages are unchanged.

## 1. Acquire without running hooks

Expand Down Expand Up @@ -123,9 +124,35 @@ Same split: a networked acquisition, then a build with no network in any
`requirements.txt` with `--no-index --require-hashes`, then the two local
wheels with `--no-index --no-deps`. The live console stages are unchanged.

Known gap for the app-start proof: system libraries are absent (for example
`import cv2` needs `libxcb.so.1`), and the app writes `/app/traces` as UID
10001. Neither is handled here.
## App-start proof

The preview image must start with no network, as UID 10001. The host daemon
supplies what the image does not: a writable `ARTEMIS_APP_DIR` parent (`/app`
is not writable by the preview user), a writable `/tmp`, the Cloudflare Access
settings and a public JWKS bundle (`ARTEMIS_PREVIEW_JWKS_BUNDLE`), and the
fixture emails. Run on X99 with a throwaway key; the token is signed by the
same key:

```sh
docker run -d --name proof --network none \
--tmpfs /tmp:uid=10001,gid=10001 --tmpfs /scratch:uid=10001,gid=10001,mode=700 \
-v "$PWD/proof:/proof:ro" -e ARTEMIS_APP_DIR=/scratch \
-e ARTEMIS_AUTH_MODE=cloudflare -e ARTEMIS_CF_ACCESS_AUD=proof-aud \
-e ARTEMIS_CF_ACCESS_TEAM_DOMAIN=proof -e ARTEMIS_PREVIEW_JWKS_BUNDLE=/proof/jwks.json \
-e ARTEMIS_ADMIN_EMAILS=admin@example.test \
-e ARTEMIS_PREVIEW_QA_EMAILS=qa1@example.test,qa2@example.test <image>
```

Result (image `sha256:ee11b581262fda4bcdf11bd8922deab0af6de8537aabbedd49768cbd86bb3641`,
`Config.User` `10001:10001`): the server logs "Application startup complete".
From inside the container, `GET /` returns 401 without the
`Cf-Access-Jwt-Assertion` header and 200 with a valid token;
`GET /api/system/readiness` returns 200 with the token.

Negative proof: append `notinwheelhouse==1.0 --hash=sha256:00...00` to a
copy of `requirements.txt` in the `preview-python-inputs` context. The build
fails at `pip install --no-index` with
`ERROR: No matching distribution found for notinwheelhouse==1.0` (exit 1).

## Checks

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dependencies = [
"sseclient-py>=1.8.0",
# Image, Video & Multimodal Perception
"pillow>=10.0.0",
"opencv-python>=4.9.0.80",
"opencv-python-headless>=4.9.0.80",
"imageio-ffmpeg>=0.5.1",
"matplotlib>=3.8.0",
"numpy>=1.26.0",
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/preview_host/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ def test_preview_installs_python_only_from_the_verified_wheelhouse():
re.M,
), project
assert "pip install --no-cache-dir --no-index --require-hashes" in wheel_runs
# setup.py ships device_lease and the admin console imports it at startup.
assert "COPY device_lease/ ./device_lease/" in stages["preview-wheel-builder"].decode()
preview = re.sub(r"\\\n\s*", " ", stages["preview"].decode())
assert re.search(
r"^RUN --network=none .*from=preview-python-inputs.* pip install .*--no-index --require-hashes .*-r \S*requirements\.txt",
Expand All @@ -438,6 +440,22 @@ def test_preview_installs_python_only_from_the_verified_wheelhouse():
)


def test_opencv_is_the_headless_build_in_pyproject_and_lock():
"""GUI OpenCV needs libxcb, libGL and libglib, which python:3.12-slim lacks (CHE-9898)."""
import tomllib

names = [
re.split(r"[<>=!~ ;\[]", dep, 1)[0].lower().replace("_", "-")
for dep in tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["dependencies"]
]
assert "opencv-python-headless" in names
assert not {"opencv-python", "opencv-contrib-python"} & set(names)
packages = tomllib.loads((ROOT / "uv.lock").read_text())["package"]
locked = {package["name"] for package in packages}
assert "opencv-python-headless" in locked
assert not {"opencv-python", "opencv-contrib-python"} & locked


def _stages() -> dict[str, bytes]:
source = (ROOT / "Dockerfile").read_bytes()
starts = list(re.finditer(rb"^FROM\s+\S+(?:\s+AS\s+(\S+))?$", source, re.M))
Expand Down
29 changes: 15 additions & 14 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading