Skip to content

feat(sdk): start sandbox from Dockerfile via Image.from_dockerfile#931

Closed
Issac-Newton wants to merge 2 commits into
alibaba:masterfrom
Issac-Newton:feature/start-from-dockerfile
Closed

feat(sdk): start sandbox from Dockerfile via Image.from_dockerfile#931
Issac-Newton wants to merge 2 commits into
alibaba:masterfrom
Issac-Newton:feature/start-from-dockerfile

Conversation

@Issac-Newton

Copy link
Copy Markdown
Collaborator

fixes #531

Summary

  • New Image declarative type (rock/sdk/sandbox/image.py) with Image.base() and Image.from_dockerfile() factories. SandboxConfig.image accepts str | Image; resolution to a tag string happens transparently inside Sandbox.start() so admin / db schemas stay untouched.
  • _ImageResolver orchestrates DinD build/push inside a builder sandbox: cache check via docker manifest inspect + content-hash label, build with rock.content_hash baked in, push with credentials supplied by the Image. Builder lifecycle is split into create_builder() / resolve() / resolve_with_builder() so callers (e.g. tests) can manage the builder themselves and inject environment-specific setup before the build runs.
  • Sandbox.start() syncs the Image's registry credentials to SandboxConfig so admin can pull the just-pushed image.
  • New ImageBuilder (rock/sdk/builder/image_builder.py) implementing the EnvBuilder interface for use from non-SDK call sites (e.g. Harbor flow).
  • Default ROCK_IMAGE_BUILDER_IMAGE points to rock-env-builder:latest which has a non-conflicting docker0 (bip=192.168.250.1/24) so inner dockerd doesn't collide with the outer admin's docker0 (172.17/16); also pre-configures insecure-registries for local CIDRs so test registries work.

Spec / Design

Test plan

  • pytest tests/integration/sdk/sandbox/test_image_build.py -m need_admin — 3/3 PASSED
    • test_from_dockerfile_build_and_start — build + push + start sandbox + verify COPY'd file
    • test_from_dockerfile_cache_skip — second build of same Image hits cache (CACHE_HIT), skips push
    • test_from_dockerfile_rebuilds_on_content_change — content_hash change triggers rebuild
  • pytest tests/integration/sdk/builder/test_image_builder.py -m need_adminImageBuilder.build against local registry
  • Run fast suite to confirm no regression: uv run pytest -m "not need_ray and not need_admin and not need_admin_and_network" --reruns 1

Notes for reviewers

  • Test integration uses a fixture-managed local_registry on localhost:port. From inside the builder sandbox (own netns), localhost is its own loopback so push needs an iptables OUTPUT DNAT to the host bridge IP plus POSTROUTING MASQUERADE; the test installs this via _inject_loopback_nat before calling resolve_with_builder. Production path (admin pulls from a real registry) is unaffected.
  • The new builder image is rock-n-roll-registry.cn-hangzhou.cr.aliyuncs.com/rock/rock-env-builder:latest (digest sha256:9bf940765b2b...). It carries the bip + insecure-registries daemon.json fixes and the ulimit-tolerant init.d.

🤖 Generated with Claude Code

@Issac-Newton Issac-Newton force-pushed the feature/start-from-dockerfile branch from 8ac6e5f to fa0f985 Compare May 12, 2026 02:28
@Issac-Newton Issac-Newton force-pushed the feature/start-from-dockerfile branch 2 times, most recently from c6c851b to 80311e3 Compare June 1, 2026 04:01
Issac-Newton and others added 2 commits June 1, 2026 12:05
Add Image declarative class with from_dockerfile() factory and a unified
sandbox.ImageBuilder that resolves builds via a DinD builder sandbox.
SandboxConfig accepts Image as input; Sandbox.start() builds and pushes
the image, then syncs registry credentials to admin so it can pull.

Includes specs (requirement / investigation / implementation) and
integration tests that drive the build via a test-managed builder with
iptables loopback NAT, so a local registry on 127.0.0.1 is reachable
from inside the builder's network namespace.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…y/tag

Replace the single-string image_name auto-generation in from_dockerfile()
with explicit 4-segment composition: registry_url / namespace /
repository : tag. Repository defaults to SandboxConfig.user_id (or
"default" fallback), injected by Sandbox.start(). Tag uses the full
64-hex SHA-256 of the build context, matching the OCI digest standard
for collision safety.

Add ROCK_IMAGE_NAMESPACE env var (default "rock") and thread
Image._resolve_full_name() through ImageBuilder so dockerfile-based
images compose the registry tag once.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Issac-Newton Issac-Newton force-pushed the feature/start-from-dockerfile branch from 80311e3 to a591513 Compare June 1, 2026 04:05
@Issac-Newton

Copy link
Copy Markdown
Collaborator Author

Superseded — history was rewritten (squashed 16 commits → 2, dropped one unrelated commit). Reopening as a fresh PR for clean review. New PR will be linked in the next comment.

@Issac-Newton

Copy link
Copy Markdown
Collaborator Author

Replaced by #1043.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Start Sandbox From Dockerfile

1 participant