Skip to content

feat(harbor): add openenv harbor build-images for OCI registries and Kaniko on HF Jobs - #1757

Open
burtenshaw wants to merge 18 commits into
mainfrom
feat/harbor-build-images
Open

burtenshaw wants to merge 18 commits into
mainfrom
feat/harbor-build-images

Conversation

@burtenshaw

Copy link
Copy Markdown
Collaborator

Summary

Adds openenv harbor build-images (openenv.harbor.images) to turn Harbor task directories into HF-Sandbox-ready tasks with digest-pinned, publicly pullable linux/amd64 [environment].docker_image references in task.toml — targeting standard OCI registries (GHCR, Docker Hub, etc.) with no Docker Spaces required.

openenv harbor build-images <path> --registry ghcr.io/<org>/<repo>
  ├── discover_task_dirs          # single task or flat/nested Harbor dataset
  ├── audit_environment           # blocks symlinks, ../tests/solution COPYs, leaked verifier/solution bytes, tokens
  ├── plan_harbor_images          # content-hash deduplication + Dockerfile classification
  │     ├── no Dockerfile         -> verify_shared / keep_pinned (Harbor auto-uploads environment/)
  │     ├── COPY/WORKDIR/ENV only -> OCIRegistryClient.append_layer (pure-Python OCI v2, no daemon/Jobs, <1s/task)
  │     └── RUN / multi-stage     -> KanikoHFJobsBuilder (HF Jobs + bucket tar context) or DockerBuildxBuilder
  ├── verify_harbor_images        # anonymous linux/amd64 manifest + config check (HF Sandbox preflight)
  └── update_task_toml + receipts # atomic [environment].docker_image pin + resumable per-task & manifest receipts
 src/openenv/
 ├── cli/commands/
 │   └── harbor.py                # + `openenv harbor build-images` (--plan, --verify-only, --builder kaniko|docker|oci-append, --per-task-receipts-dir, --task)
 └── harbor/
     ├── __init__.py              # documents images.py
+    └── images.py                # OCI v2 client, Dockerfile classifier, audit, pure-Python OCI append, Kaniko HF Jobs & Docker Buildx builders
 tests/test_cli/
+└── test_harbor_build_images.py  # 11 unit tests covering parsing, audit, OCI append, Kaniko Jobs, Buildx, task.toml rewrite, dedup & resume

Evidence

  • Before: Running Harbor tasks on hf-sandbox failed unless each task's task.toml manually pinned a prebuilt public docker_image; per-task builds had to use ad-hoc VMs or 1-Docker-Space-per-task scripts.
  • After:
    • Unit tests & lint: pytest tests/test_cli/test_harbor_build_images.py tests/test_line_endings.py (18 passed), ruff check and ruff format clean.
    • Live Kaniko on HF Jobs (cpu-basic, no nested Docker):
      • openenv harbor build-images <task> --builder kaniko --namespace burtenshaw --no-push completed end-to-end on HF Job 6b083edad91f621b930b384b (private staging bucket tarball upload → Kaniko pip install + RUN → sha256: digest capture → bucket cleanup).
      • Also verified apt-get, useradd/chown, and --custom-platform=linux/amd64 on HF Jobs 6b083c20d91f621b930b3190, 6b083c57b6a90bbe998086ef, and 6b083cd6b6a90bbe9980888a.
    • Live pure-Python OCI layer append against real registry:2: pulled docker.io/library/python@sha256:5e2bdb..., appended a COPY layer + WORKDIR/ENV, stamped task.toml, passed --verify-only --require-digest-pin, and ran the pushed digest in docker run --platform linux/amd64.
    • Live GHCR preflight: --verify-only --require-digest-pin resolved a multi-arch ghcr.io image index to linux/amd64 anonymously.

Merge Danger

Door: Two-way

Additive CLI subcommand (openenv harbor build-images) and new module (openenv.harbor.images) using existing core dependencies (httpx, huggingface_hub, tomli/tomllib). No existing commands, schemas, or runtime dependencies change.

Blast Radius: Isolated

Only affects callers invoking the new openenv harbor build-images subcommand or importing openenv.harbor.images.

Made with Cursor

@burtenshaw burtenshaw added feature size: extra-large Extra-large pull request labels Nov 26, 2026 — with Cursor
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The docs for this pull request are available at https://openenv.github.io/OpenEnv/pr-preview/pr-1757/ (commit 5acc7e7). The preview may take a minute to update and is removed when the pull request closes.

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/cli/commands/harbor.py Resolved

@cursor cursor Bot 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.

Alignment Review Report

Automated Checks

  • Lint: FAIL — usort check src/ tests/ flags import-sort order in all three new/changed files (src/openenv/harbor/images.py, src/openenv/cli/commands/harbor.py, tests/test_cli/test_harbor_build_images.py). ruff format --check and ruff check are clean for this diff (the one ruff format hit, src/openenv/core/harness/README.md, and the two pre-existing usort hits in tests/envs/test_grid_world.py/test_julia_env.py, are unrelated to this PR per AGENTS.md).
  • Debug code: CLEAN — check-debug.sh finds no print/breakpoint/TODO debug code in the new files (only docstring examples and a pre-existing unrelated TODO elsewhere).
  • Tests: tests/test_cli/test_harbor_build_images.py passes (11/11) against an in-memory fake OCI registry — no live network calls, good isolation.

Open RFCs Context

  • RFC 008 (In Review) already defines digest-pinned environment.docker_image semantics that openenv validate consumes; this PR's output (<repo>@sha256:<digest>) matches that contract.
  • RFC 014 (In Review, "Environment Services") defines a broker pattern for agent-facing, episode-time HF Jobs usage (credentials never reach agent code, run_uv_job over hf jobs uv run, budgets, job handles). This PR's KanikoHFJobsBuilder is a separate, operator-run, pre-rollout build tool — not reachable by any agent or episode — so RFC 014's broker/budget rules don't strictly apply, but it is a second independent HfApi Jobs integration in the codebase (run_job + create_bucket/batch_bucket_files, following the existing pattern already used in harbor.py's push command and ui_data.py). Noting for awareness since RFC 014 is actively shaping HF Jobs conventions here.

Tier 1: Fixes Required

  • src/openenv/harbor/images.py:46 — import order: usort wants as_completed, ThreadPoolExecutor (alphabetical).
  • src/openenv/cli/commands/harbor.py:507-512 — import order inside the lazy from openenv.harbor.images import (...) block.
  • tests/test_cli/test_harbor_build_images.py:18-32 — import order (lowercase helper functions should sort before the capitalized classes per usort).
  • docs/source/environments/harbor.md (## CLI reference section, currently only documents info/rollout/serve/push around lines 393-519) and docs/source/reference/cli.md's command table (lines 468-471) — neither documents the new build-images command. Worth a follow-up doc pass (/update-docs) since this introduces a new public, user-facing CLI command with ~20 flags.

All four are mechanical — running uv run usort format src/ tests/ fixes the first three.

Tier 2: Alignment Discussion

Principle Conflicts

None identified. This is a standalone, operator-invoked build/push/verify pipeline over the Harbor task's environment/ directory and task.toml; it never runs inside, nor is reachable from, an agent's rollout. It doesn't touch reset/step/state, the MCP boundary, reward computation, or client/server separation. The security hygiene is notably careful: audit_environment scans for embedded credentials/private keys, symlinks, path traversal and verifier/solution leakage before anything is built or pushed; manifest/blob/config digests are independently verified at every hop; registry auth headers are dropped on cross-origin redirects; and secrets passed into Kaniko jobs are written to a file inside the job, used once, and unset.

RFC Conflicts

None blocking. See the RFC 014 note above — flagged only as a design-consistency point for whoever is tracking HF Jobs integration conventions across the codebase (@rycerzes, RFC 014 author), not a conflict with anything this PR does.

Summary

  • 3 mechanical lint fixes (import order) + 1 doc-completeness gap to fix
  • 0 principle-conflict alignment points for human review
  • 0 blocking RFC conflicts (1 non-blocking awareness note re: RFC 014 / HF Jobs conventions)
Open in Web View Automation 

Sent by Cursor Automation: Pre-review

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: ** COPY globs never fall back
    • Dockerfile classification now marks recursive ** COPY source globs as unsupported for OCI append so auto builder selection falls back to Kaniko or Buildx.

You can send follow-ups to the cloud agent here.

Comment thread src/openenv/harbor/images.py Resolved
cursoragent and others added 6 commits November 26, 2026 15:08
compute_environment_hash covered every file under environment/, so tasks with
the same Dockerfile but different files the Dockerfile never reads (e.g. a
source tree Harbor uploads at runtime) got different hashes and were each
built and pushed again. On harness-hub/harness-adapters scale800_v1, 847 tasks
share 14 Dockerfiles, none with COPY: 14 builds instead of hundreds.

The hash now covers the Dockerfile and the files its COPY/ADD instructions read
from the context. It falls back to the whole context when that cannot be told
statically (RUN --mount, ARG-expanded or recursive '**' sources).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt hash

Addresses the Bugbot review on #1758:
- split instructions and COPY/ADD flags on any whitespace, like classify_dockerfile
- hash .dockerignore with the copied files, since Kaniko and Buildx filter the context through it
- fall back to the whole context for heredoc Dockerfiles, whose bodies are not instructions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g everything

Addresses the follow-up Bugbot review on #1758: any `<<` (RUN heredocs,
comments, --extra-dockerfile snippets) forced a full-context hash, bringing
back the per-task rebuilds this change removes. Heredoc bodies are now
skipped before parsing and COPY/ADD heredoc sources are ignored, since their
payload lives in the already-hashed Dockerfile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ied-files

fix(harbor): hash only what build-images copies into the image
@cursor cursor Bot mentioned this pull request Nov 30, 2026
2 tasks done
cursoragent and others added 4 commits December 2, 2026 11:43
Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
…ed stub

Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 4 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for all 4 issues found in the latest run.

  • ✅ Fixed: Registry auth sent to upload Location
    • Registry credentials are now attached and negotiated only for URLs on the registry host, preventing cross-host upload locations from receiving authorization.
  • ✅ Fixed: Resume ignores sibling env receipts
    • Resume now searches every member of a deduplicated environment group for a valid resolved receipt.
  • ✅ Fixed: ENV values skipped in path expansion
    • Dockerfile path and metadata expansion now uses previously declared ENV values together with ARG values.
  • ✅ Fixed: OCI append skips dockerignore rules
    • OCI COPY layer construction now applies Docker ignore patterns, including exclusions, negations, and recursive matches.

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 81a472e. Configure here.

Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/harbor/images.py Resolved
Comment thread src/openenv/harbor/images.py Resolved
cursoragent and others added 4 commits December 2, 2026 12:01
… OCI append for unresolved vars and .dockerignore, resume from any dedup sibling

Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
…of a hand-rolled ignore matcher

Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>
Co-authored-by: burtenshaw <burtenshaw@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature size: extra-large Extra-large pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants