Skip to content

feat(harbor): Dockerfile builds, the third image mode (RFC M20) - #4566

Merged
adil-a merged 2 commits into
adasif/harbor-m17-comparefrom
adasif/harbor-m20-dockerfile-builds
Oct 21, 2026
Merged

adil-a merged 2 commits into
adasif/harbor-m17-comparefrom
adasif/harbor-m20-dockerfile-builds

Conversation

@adil-a

@adil-a adil-a commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

RFC milestone M20. Three image modes decided per Dockerfile at prepare: pull, overlay (M16) and now build.

  • Build mode keys on a digest of the task's environment/ context (executable bits included), builds once with buildah, podman or docker, pushes when --build-repository is set (buildah and podman require it, since their stores are private; docker is the laptop path), records built-images.json next to the task folders and the image's OCI config in compose-images.json, and the loader runs the task in pull mode from the recorded image.
  • Build settings live in a builds: block of the merged config (env.yaml, a --config file, or ++builds.<key>=...): tool (buildah, podman or docker, default the first on PATH), repository (default NEMO_GYM_BUILD_REPOSITORY), platform (default linux/amd64, with a pre-record check that the built image matches) and enabled (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 final USER becomes the default user for every exec through the sandbox facade and the descriptor, applied after the overlay has created it. Docker no longer passes --user at docker run. Compose sidecars keep their own image user. Numeric users resolve to a name.
  • Distinct images of a prepared taskset are written to <results>/<taskset>/images.json for 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-platform with emulation. Reviewed in two DA plus verify rounds, 9 findings fixed.

Stacked on #4565 (M19). Pulled hub datasets land in the gitignored ./datasets folder ($NEMO_GYM_DATASETS_DIR). dataset.toml is read beside the task folders, or one level up for a <name>/tasks/ layout, in build_plan.py and image_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 --files on 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.md on Lustre, every item reproduced with a real run before and after):

  • buildah and podman get a registries.conf with unqualified-search-registries = ["docker.io"], so FROM oven/bun:1 resolves as docker would. 2,157 sampled tasks in 43 datasets failed without it.
  • buildah and podman build with --format docker. The OCI format ignores SHELL during the build and drops HEALTHCHECK and ONBUILD. 106 tasks whose RUN lines need the declared shell built wrong.
  • A heredoc preflight. Ubuntu's packaged buildah 1.33.7 cannot parse Dockerfile heredocs. The build now fails once with the tool version and the remedy instead of a silent "Unknown instruction".
  • services.main.build (context, dockerfile, args, target) is honoured on the direct path, as docker compose honours it.
  • Prepare failures are per task. One bad task goes to skipped.json with its reason instead of aborting the dataset.
  • built-images.json and compose-images.json are 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.
  • The Compose field check the sandbox adapter applies at seed now runs at prepare and records the offending field per task. pull_policy is stripped for every service.
  • Plain tasks run their image ENTRYPOINT at seed, as Harbor's docker compose up does. The entrypoint runs detached as the image user with sh -c "sleep infinity", its exit status and log are captured, the recorded HEALTHCHECK is 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.
  • Task [environment].env wins over a Compose file's main.environment, matching Harbor's merge order.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@adil-a
adil-a added this pull request to stack #3808 October 13, 2026 15:18

@yuhezhang-ai yuhezhang-ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --check passed.
  • 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.

Comment thread environment_servers/harbor/app.py Resolved
Comment thread environment_servers/harbor/app.py Resolved
Comment thread nemo_gym/tasks/harbor/digest.py Resolved
Comment thread nemo_gym/sandbox/api.py Resolved
Comment thread nemo_gym/sandbox/api.py Resolved
Comment thread nemo_gym/tasks/harbor/cli.py Resolved
Comment thread nemo_gym/tasks/harbor/cli.py Resolved
@adil-a
adil-a removed this pull request from stack #3808 October 14, 2026 00:54
@adil-a
adil-a added this pull request to stack #4583 October 14, 2026 00:55
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch from 19cf89b to 5941a2f Compare October 14, 2026 01:07
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch from 5941a2f to f9d140b Compare October 14, 2026 01:33
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch from f9d140b to 76fc94c Compare October 14, 2026 01:39
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch 2 times, most recently from 5ece104 to ae08f56 Compare October 14, 2026 16:29
@adil-a
adil-a marked this pull request as ready for review October 14, 2026 16:49
@adil-a
adil-a requested a review from a team as a code owner October 14, 2026 16:49
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch from ae08f56 to 2270f87 Compare October 14, 2026 17:00
@adil-a

adil-a commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2270f87

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 14, 2026 17:02
@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Oct 14, 2026
@yaoyu-33 yaoyu-33 added the area:build Packaging, dependencies, containers, and releases label Oct 14, 2026
@adil-a
adil-a force-pushed the adasif/harbor-m20-dockerfile-builds branch from d8bfb00 to f5c69cb Compare October 20, 2026 00:20
@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f5c69cb

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e64503b

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 19affb2

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cdbef54

@adil-a

adil-a commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

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.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7cb30e9

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4d22a13

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c1ba8ca

yuhezhang-ai
yuhezhang-ai previously approved these changes Oct 21, 2026

@yuhezhang-ai yuhezhang-ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 08bed3f

ffrujeri
ffrujeri previously approved these changes Oct 21, 2026

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, ssh and extra_hosts;
  • network: host;
  • additional_contexts other than service: references;
  • cache_from/cache_to entries carrying credentials;
  • include, and extends with a file;
  • 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.

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 940acec

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/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]>
@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 25477d1

ffrujeri
ffrujeri previously approved these changes Oct 21, 2026

@ffrujeri ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7edcb3e

@adil-a

adil-a commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

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 ffrujeri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39689230539

This branch was previously deployed

1 inactive deployment
public — 7edcb3e9 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6460
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:build Packaging, dependencies, containers, and releases complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work QA_verified waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants