Skip to content

feat(orchestrator): add export-build command (#3272)#3291

Open
AdaAibaby wants to merge 6 commits into
e2b-dev:mainfrom
AdaAibaby:feat/export-build-rootfs-as-docker-image
Open

feat(orchestrator): add export-build command (#3272)#3291
AdaAibaby wants to merge 6 commits into
e2b-dev:mainfrom
AdaAibaby:feat/export-build-rootfs-as-docker-image

Conversation

@AdaAibaby

Copy link
Copy Markdown
Contributor

Summary

Implements #3272 — export template/sandbox rootfs as a Docker image.

  • cmd/export-build/main.go — new CLI tool that mounts a template rootfs via the NBD block-device pipeline and writes it as a Docker-loadable OCI tar archive or pushes it to a container registry
  • cmd/internal/cmdutil/template.go — adds E2B_API_URL env var for self-hosted deployments where the API lives at a non-standard host (e.g. http://localhost:3000); extracted resolveAPIURL() for testability
  • cmd/export-build/main_test.go + cmd/internal/cmdutil/template_test.go — 17 unit tests covering storage resolution priority chain and all ResolveTemplateID code paths via httptest

Usage

Set env vars once (e.g. in ~/.bashrc):

export TEMPLATE_STORAGE_URL="s3://bucket?endpoint=https://...&region=..."
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_REGION=...
export E2B_API_KEY=e2b_...
export E2B_API_URL=http://localhost:3000   # self-hosted / local dev

Then export by template alias:

sudo -E export-build -template my-alias -output /tmp/rootfs.tar
docker load -i /tmp/rootfs.tar

# or push directly to a registry
sudo -E export-build -template my-alias -push registry.example.com/img:v1

Storage URL priority: -storage flag → TEMPLATE_STORAGE_URL env → legacy STORAGE_PROVIDER+TEMPLATE_BUCKET_NAME env.
API URL priority: E2B_API_URLE2B_DOMAINhttps://api.e2b.dev.

Prerequisites

modprobe nbd max_part=8   # already loaded on orchestrator nodes

Test plan

  • go test ./cmd/export-build/ ./cmd/internal/cmdutil/ passes (17 tests)
  • sudo -E ./export-build -template <alias> -output /tmp/out.tar produces a loadable tar
  • docker load -i /tmp/out.tar && docker run --rm <image> ls / shows rootfs contents

…s as Docker image

Implements issue e2b-dev#3272.

Adds a new CLI tool packages/orchestrator/cmd/export-build that reads an
E2B template rootfs from object storage via the NBD block-device pipeline
and writes it as a Docker-loadable OCI tar archive or pushes it directly
to a container registry.

Key changes:
- cmd/export-build/main.go: new command with -build/-template/-storage/
  -output/-push/-tag flags. Storage and API endpoint are env-configurable
  so the minimal invocation is just two flags:
    sudo -E export-build -template <alias> -output /tmp/rootfs.tar
- cmd/internal/cmdutil/template.go: extract resolveAPIURL() and add
  E2B_API_URL env var (highest priority) so self-hosted deployments with
  a non-standard API host (e.g. http://localhost:3000) work without a
  domain suffix.
- cmd/internal/cmdutil/template_test.go: 12 unit tests covering URL
  resolution priority and all ResolveTemplateID code paths via httptest.
- cmd/export-build/main_test.go: 5 unit tests covering resolveSpec
  priority chain (flag URL > env var > legacy env).

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the export-build CLI tool to export template rootfs images from E2B object storage as Docker-loadable OCI tar archives or push them to a container registry, alongside supporting updates to API URL resolution. Feedback highlights critical issues with deferring cleanup functions before checking for errors, which could lead to nil pointer dereferences, and recommends using a non-cancellable context for cleanups to ensure they run on interruption. Additionally, it is suggested to lowercase default image tags to avoid Docker repository validation errors and to add a timeout to the template resolution HTTP request to prevent indefinite hangs.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/orchestrator/cmd/export-build/main.go
Comment thread packages/orchestrator/cmd/export-build/main.go
Comment thread packages/orchestrator/cmd/export-build/main.go
Comment thread packages/orchestrator/cmd/export-build/main.go
Comment thread packages/orchestrator/cmd/internal/cmdutil/template.go Outdated
AdaAibaby and others added 2 commits July 15, 2026 18:52
- cleanup: check error before defer, run cleanup with nbdCtx on early
  return so cleanups are not skipped on failure. Note: all three helpers
  (TemplateRootfs, GetNBDDevice, MountNBDDevice) always return a non-nil
  Cleaner, and Cleaner.Run internally calls context.WithoutCancel so the
  cancel signal does not affect cleanup; the pattern change is for clarity
  and defensive correctness.
- tag: normalise default image tag to lowercase (strings.ToLower) to
  satisfy Docker repository naming rules when the template alias contains
  uppercase letters.
- template API: add 15s timeout to the template-resolution HTTP request
  to prevent indefinite hangs when the API is slow or unreachable.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e8232d641

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/orchestrator/cmd/export-build/main.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31d9749292

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/orchestrator/cmd/export-build/main.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants