Repository navigation
feat(harbor): Dockerfile builds, the third image mode (RFC M20) - #4566
Conversation
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Reviewed M20 at 19cf89b3634b060ff6e272d7327c2e197ac039a2 against its M19 parent (#4565), 07250b2fcf2d34bc1c16fca97a6cb7f787a0b94c.
The build mode lets a task that copies a helper into its image be prepared and reused directly. The six P2 comments identify issues in the new default-user behavior, build-cache identity, and pre-pull manifest that should be fixed before readiness. The P3 cached-build-tool comment is nonblocking.
The Harbor server tests currently store default_user in their fake sandbox but do not apply it in exec. That omits the production behavior responsible for several of the user regressions. Please cover effective execution identity when fixing these paths.
Validation performed during this review:
- Core:
.venv/bin/pytest tests/unit_tests/test_harbor_image_build.py tests/unit_tests/test_harbor_tasks.py tests/unit_tests/test_cli_main.py tests/unit_tests/test_sandbox.py tests/unit_tests/test_sandbox_connect.py tests/unit_tests/test_docker_provider.py tests/unit_tests/test_docker_compose.py -q --cpu -k 'not test_buildah_builds_a_real_image_rootless'— 659 passed, 2 skipped, 1 deselected. - Harbor server:
.venv/bin/gym env test --resources-server harbor— 71 passed. - Targeted Ruff and
git diff --checkpassed. - Additional focused probes confirmed wrong-user dispatch, cache reuse after meaningful context changes, missing manifest entries, and the cached-build/no-tool failure. Pi and Daytona probes exercised the actual harness/facade/provider code with external execution simulated, as described inline.
- No live model rollout, real image build/push, or hosted-provider end-to-end run was performed.
An independent Claude review delivered its report, but its execution verification remains incomplete because a shell command failed during sandbox startup. Codex independently checked the material findings; this should not be read as a fully verified dual-review run.
Scope and exclusions: M1–M3 repairs remain lower-stack dependencies and need affected checks after the stack is updated. The absent datasets/<name>/tasks/ lookup is inherited from M19; the misleading comments are a minor documentation correction. Claude's Compose failures reproduced at both base and head due to its temporary-directory permissions; the Codex Compose run passed. Build timeouts, shared Buildah storage, and concurrent record writes remain follow-up concerns without a demonstrated workload failure in this review.
19cf89b to
5941a2f
Compare
5941a2f to
f9d140b
Compare
f9d140b to
76fc94c
Compare
5ece104 to
ae08f56
Compare
ae08f56 to
2270f87
Compare
|
/ok to test 2270f87 |
d8bfb00 to
f5c69cb
Compare
|
/ok to test f5c69cb |
|
/ok to test e64503b |
|
/ok to test 19affb2 |
|
/ok to test cdbef54 |
|
Status at the new head cdbef54. The two threads left on 19 Oct and the new one are answered inline. User groups are kept: agent:shared is installed as the sandbox default and every Docker exec gets --user agent:shared, uid:gid keeps its group behind the resolved name, and on providers that switch user by name only a name:group is refused with a 422 naming the task, the group and the provider before the sandbox exists (TestUserNormalisation, and test_exec_keeps_the_group_of_the_default_user in tests/unit_tests/test_docker_provider.py repeats your probe through the facade and the provider). Cache validity rests on a separate inputs digest over the whole context tree with lstat modes, link targets, empty folders and the ignored names, plus the resolved build section and arguments, so hb__ stays the name and reuse needs both to match (tests/unit_tests/test_harbor_build_inputs.py). CMD-SHELL healthchecks run through the image's recorded Shell. On effective execution identity, the coverage you asked for sits at the facade layer, test_exec_defaults_to_the_spec_user_and_an_explicit_user_wins in tests/unit_tests/test_sandbox.py and the Docker provider test above. The server fake still records the exec user rather than applying a default. The five you resolved on 19 Oct and the --no-build platform check are unchanged by the rebase. |
|
/ok to test 7cb30e9 |
|
/ok to test 4d22a13 |
|
/ok to test c1ba8ca |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
All findings from this review are addressed in M20 and the included M24 (#4689 at 530416d4). The cache-grouping fix lives in M24, so this approval assumes those changes ship together.
Validation: 117 focused tests passed across M20 and M24, plus the shared/separate grading and conflicting-context reproductions. The required DCO, lint, and Nemo_CICD_Test checks pass at c1ba8ca0; the core tests and all eight server-test shards also pass. Optional harness-conformance checks remain red, with the same failing check names on the M19 base.
The focused reproductions used simulated external execution/builds; I did not run live containers or model rollouts in this follow-up.
|
/ok to test 08bed3f |
ffrujeri
left a comment
There was a problem hiding this comment.
Approving 08bed3f7. I focused on what a third-party task can ask of the build host. validate_task_compose runs on the document after interpolation (so network: ${X:-host} cannot slip through), confines contexts and Dockerfiles to environment/, and refuses the following:
secrets,sshandextra_hosts;network: host;additional_contextsother thanservice:references;cache_from/cache_toentries carrying credentials;include, andextendswith afile;- sidecar builds.
Subprocesses go through the one Runner seam. The build, Compose, records, entrypoint and Harbor suites pass locally (902 passed). The 5 local failures are the 127.0.1.1 hostname tests flagged on #3746, and CI is green apart from the non-blocking conformance probes. As Yu noted, the cache-grouping fix lives in M24 (#4689, draft), so this should land together with it.
|
/ok to test 940acec |
|
/ok to test 4b68037 |
Compose files in Harbor tasks use `${MAIN_IMAGE_NAME}`, `${CONTEXT_DIR}` and `${VAR:-default}`
templates and `env_file` entries. Preparing the dataset and the environment server now read the
Compose file through one resolver: `env_file` is inlined into `environment`, and variables
resolve from the task alone (the main image recorded for the task, the task's `environment/`
folder, the task's own defaults), never from the server's process environment. The server
resolves against its task snapshot, so bind mounts point into that copy.
Squashed from the previous branch and re-applied onto the environment server.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
|
/ok to test 25477d1 |
ffrujeri
left a comment
There was a problem hiding this comment.
Re-approving 25477d1e. Beyond the restack, the README now states the os.environ trust boundary of compose_variables(), which covers my note on #4565. At this head the stack suites pass locally (985 passed). The two remaining local failures are test_partial_eval_*[True], which still resolve the real hostname (127.0.1.1 on Ubuntu); they could pin gethostbyname the same way #3746 does. As before, this should land together with the cache-grouping fix in #4689.
Prepare decides one of three image modes per distinct Dockerfile. Pull and overlay exist; this
adds build. A task whose Dockerfile needs a build (`COPY`, `ADD`, heredocs, BuildKit flags) is
built once from its `environment/` folder with buildah, podman or docker, pushed when a
repository is named, and recorded in `built-images.json` next to the task folders, keyed by the
digest of the build context. The built image's OCI configuration is recorded in
`compose-images.json` like any pulled image, so the loader runs the task in pull mode with the
Dockerfile's final `WORKDIR`, `ENV` and `USER`. Builds are cancel-safe and recorded contexts are
never rebuilt. The environment server's task snapshot carries `built-images.json` with the other
dataset-level files, so a build-mode task seeds from its recorded image.
`gym eval run` and `gym dataset validate` build the selected tasks' Dockerfiles before the tasks
load (`--build-tool`, `--build-repository` / `NEMO_GYM_BUILD_REPOSITORY`, `--build-platform`,
`--no-build`, `--rebuild`) and print the distinct images for pre-pulling.
The sandbox facade gains a default exec user: the Dockerfile's final `USER` (or `[agent].user`)
is the default for every exec in the task's own image, set after an overlay has run (its `RUN`
lines may be what creates the user), with a numeric uid resolved to its name; sidecars and a
separate verifier in another image keep their own image's default. Root-first execs ask for root
explicitly whenever either the image user or the sandbox default is not root.
Squashed from the previous branch and re-applied onto the environment server.
The docker backend is Harbor's build step. For the Docker provider, prepare writes the Compose file
Harbor's Docker environment builds a task with (service `main`, `build.context` the task's
`environment/` folder, `image: hb__<hash>`, the value of Harbor's `MAIN_IMAGE_NAME`, plus its
`pull_policy` and keep-alive `command`), appends the task's own `environment/docker-compose.yaml`
after it in Harbor's order, and runs `docker compose --project-directory <environment/> -f ... build`
with Harbor's variables (`MAIN_IMAGE_NAME`, `CONTEXT_DIR`, the log-mount paths) in the environment, so
`main`'s own build args and target in that file apply, as `DockerEnvironment.start()` builds it (v0.22.0, cited by permalink in `image_build.py`). `docker build`
is never called; a missing Compose plugin fails prepare with a message naming `docker-compose-plugin`.
buildah and podman stay the OpenSandbox path (direct Dockerfile build and registry push), and
`built-images.json` / `compose-images.json` are recorded as before, so the loader and the pull-mode
path are unchanged.
Review fixes (Devil's Advocate on the docker backend). The compose build environment carries the task's
`[environment].env`, resolved as Harbor's `resolve_env_vars` resolves it (`${VAR}` / `${VAR:-default}`
against the host; unset with no default fails the build), plus `CPUS` and `MEMORY` (`<n>M`), merged
os.environ < task env < infrastructure with Harbor's collision warning; tasks sharing a context but
declaring different settings build once with the first task's values and are logged. The task's Compose
file is checked before `docker compose` runs it on the build host: build `secrets`, `ssh`, `extra_hosts`,
`network: host`, `additional_contexts` other than `service:` references, cache entries carrying
credentials, a `build.context` or `dockerfile` outside `environment/` (symlinks resolved), a top-level
`include` and an `extends.file` are refused naming the service and key. Only
`environment/docker-compose.yaml`, the one file Harbor reads, is built from; the other spellings the
loader accepts at run time are refused at build time so prepare and seed cannot disagree. The generated
file no longer names `build.dockerfile` (Harbor's does not), so a task file's `dockerfile_inline` merges
as it does in Harbor. A sidecar with a `build:` section is refused at prepare, since the loader records
sidecars from their `image:` and no provider starts a locally built one, so only `main` is built. The
docstrings and README now say that Harbor's template sets no `image` (Compose tags `<session>-main`) and
that `image: hb__<hash>`, the `MAIN_IMAGE_NAME` value, is Gym's addition so the result can be inspected,
pushed and recorded.
Follow-ups from the verify round and the first end-to-end cluster build. The task Compose file is
validated as Compose reads it: interpolated against the build's own environment (the merged
`docker compose` environment, with `environment/.env` under it as Compose reads the project directory's
`.env`), with Compose's `${VAR}`, `${VAR:-default}`, `${VAR-default}`, `${VAR:?error}`, `${VAR:+alt}` and
`$VAR` forms, so `network: ${X:-host}` and `cache_to: [type=gha,${X:-token}=abc]` are refused like their
literal values and a variable the build cannot resolve is refused outright. `environment/.env` values are
expanded as Compose's dotenv reader expands them (unquoted and double-quoted values against the build's
environment and the lines above them, single-quoted values literal) before the document reads them, so
`NET=${X:-host}` in `.env` is refused like `network: host`, and `COMPOSE_ENV_FILES` in the build's environment
fails the build, as it would point Compose at files the check does not read. Prepare and seed agree on
`main`'s build section: a task that runs from its recorded built image has `build:` and `pull_policy`
dropped from `main` at seed (`image_configs.without_main_build`, via the new `HarborTask.built_image`),
since the recorded image stands in for the build those keys describe and the Compose adapter starts
images only; pull and overlay tasks are unchanged. buildah and podman run with a `containers.conf`
override (`[containers] volumes = []`, written once under the storage root and passed as
`CONTAINERS_CONF_OVERRIDE` unless the caller set one): the host's default `/etc/localtime` bind mount
reaches build steps and breaks any Dockerfile that installs tzdata. When a build, push or ping fails with
a 403, the builder logs the names (never values) of the proxy variables in the tool's environment, or
says there are none and that the tool's own configuration is the place to look; the README documents
that an inherited proxy breaks the registry ping unless `no_proxy` carries the registry host.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
|
/ok to test 7edcb3e |
|
Thanks Felipe. I reproduced the two test_partial_eval failures by pinning the resolver to 127.0.1.1 and they came from the run refusing a host that resolves to loopback, the same check #3746 ran into, so both tests now pin gethostbyname to 192.0.2.20 the way the other CLI tests in that file already do, and they pass with the real hostname and with the forced 127.0.1.1 alike. That is the only change at head 7edcb3e, the patch is otherwise identical to 25477d1, and M24 and everything above are reseated on it. Sorry to cost you one more approval click on this one. |
ffrujeri
left a comment
There was a problem hiding this comment.
Re-approving 7edcb3e9. git range-diff against 25477d1e shows only the gethostbyname pin in the two test_partial_eval_* tests. They now pass here, on a host whose name really resolves to 127.0.1.1. As before, this should land together with the cache-grouping fix in #4689.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39689230539 |
Summary
RFC milestone M20. Three image modes decided per Dockerfile at prepare: pull, overlay (M16) and now build.
environment/context (executable bits included), builds once with buildah, podman or docker, pushes when--build-repositoryis set (buildah and podman require it, since their stores are private; docker is the laptop path), recordsbuilt-images.jsonnext to the task folders and the image's OCI config incompose-images.json, and the loader runs the task in pull mode from the recorded image.builds:block of the merged config (env.yaml, a--configfile, or++builds.<key>=...):tool(buildah, podman or docker, default the first on PATH),repository(defaultNEMO_GYM_BUILD_REPOSITORY),platform(defaultlinux/amd64, with a pre-record check that the built image matches) andenabled(false skips tasks that need a build). No new CLI flags: a changed context is a new hash and rebuilds on its own, and deleting an entry from the built-images file forces a rebuild. A recorded build is reused only when it is compatible with the run (pushed state, platform).SandboxSpec.user: the task's finalUSERbecomes the default user for every exec through the sandbox facade and the descriptor, applied after the overlay has created it. Docker no longer passes--useratdocker run. Compose sidecars keep their own image user. Numeric users resolve to a name.<results>/<taskset>/images.jsonfor pre-pull.Not exercised for real: a registry push (fake tool only) and a built image on OpenSandbox end to end. Builds for the x86 pods must run on an x86 host; arm64 login nodes need
--build-platformwith emulation. Reviewed in two DA plus verify rounds, 9 findings fixed.Stacked on #4565 (M19). Pulled hub datasets land in the gitignored
./datasetsfolder ($NEMO_GYM_DATASETS_DIR).dataset.tomlis read beside the task folders, or one level up for a<name>/tasks/layout, inbuild_plan.pyandimage_configs.py. The committed dataset-folder layout is M38, not this PR.Test plan
tests/unit_tests/test_harbor_image_build.py(new, includes a real rootless buildah smoke test),test_harbor_tasks.py,test_cli_main.py,test_sandbox.py,test_sandbox_connect.py,test_docker_provider.py,test_docker_compose.py,resources_servers/harbor/tests/test_app.py: 850 unit and 71 server tests green at the top of the stack.pre-commit run --fileson the touched files.Added 16 Oct 2026, from the hub Dockerfile scan
Fixes found by building the hub's own Dockerfiles with this pipeline (report:
hub_dockerfiles_2026-10-15/REPORT.mdon Lustre, every item reproduced with a real run before and after):registries.confwithunqualified-search-registries = ["docker.io"], soFROM oven/bun:1resolves as docker would. 2,157 sampled tasks in 43 datasets failed without it.--format docker. The OCI format ignoresSHELLduring the build and dropsHEALTHCHECKandONBUILD. 106 tasks whose RUN lines need the declared shell built wrong.services.main.build(context, dockerfile, args, target) is honoured on the direct path, as docker compose honours it.skipped.jsonwith its reason instead of aborting the dataset.built-images.jsonandcompose-images.jsonare written atomically under a lock. Concurrent prepares lost entries before.image: ${MAIN_IMAGE_NAME:-x}and the other Compose spellings that resolve to the main image are accepted.pull_policyis stripped for every service.ENTRYPOINTat seed, as Harbor'sdocker compose updoes. The entrypoint runs detached as the image user withsh -c "sleep infinity", its exit status and log are captured, the recordedHEALTHCHECKis polled, and the separate verifier gets the same treatment. 557 sampled tasks in 14 datasets depended on it and scored 0 silently. This lives in M20 because it reads the built-image record.[environment].envwins over a Compose file'smain.environment, matching Harbor's merge order.🤖 Generated with Claude Code