Skip to content

Conversation

dobrac
Copy link
Contributor

@dobrac dobrac commented Aug 27, 2025

🔄 Add Template Migration to CLI

Summary

This PR introduces a new migrate command to the E2B CLI that helps users transition from the legacy Dockerfile + TOML configuration format to the new Template SDK format. The migration tool automatically converts existing e2b.Dockerfile and e2b.toml configurations into SDK-compatible template files using Handlebars templates.

What's Changed

✨ New Features

  • Template Migration Command: Added e2b template migrate command for converting legacy configurations to SDK format
  • Multi-Language Support: Supports migration to TypeScript, Python (sync), and Python (async) formats
  • Interactive Language Selection: CLI prompts for target language when not specified
  • Multi-stage Dockerfile Support: Added fallback handling for complex multi-stage Dockerfiles

🔧 Technical Improvements

  • Enhanced ENV Handling: Improved parsing of multiple environment variables from single ENV instructions
  • File Name Conflict Resolution: Automatic unique filename generation to prevent overwriting existing files
  • Comprehensive Template Generation: Creates both development and production build files

📁 New Template Files

  • typescript-template.hbs - TypeScript template generation
  • typescript-build.hbs - TypeScript build script template
  • python-template.hbs - Python template generation (supports both sync/async)
  • python-build-async.hbs - Python async build script template
  • python-build-sync.hbs - Python sync build script template

Usage

# Migrate with interactive language selection
e2b template migrate

# Migrate to specific language
e2b template migrate --language typescript
e2b template migrate --language python-sync
e2b template migrate --language python-async

# Custom paths
e2b template migrate --dockerfile custom.dockerfile --config custom.toml

Generated Output

The migration command generates three files per target:

  • template.{ts|py} - Template definition using SDK
  • build{.|_}dev.{ts|py} - Development build script
  • build{.|_}prod.{ts|py} - Production build script

Migration Process

  1. Parse Configuration: Reads e2b.toml for template settings
  2. Dockerfile Analysis: Uses E2B SDK to parse Dockerfile instructions
  3. Transformation: Converts Docker instructions to SDK method calls
  4. Code Generation: Uses Handlebars templates to generate target language files
  5. File Creation: Writes template and build files with conflict resolution

Error Handling

  • Graceful Dockerfile Parsing: Falls back to custom image reference for unparseable Dockerfiles
  • Clear User Guidance: Provides manual build instructions when automatic conversion fails
  • Validation: Ensures required configuration files exist before migration

@dobrac dobrac self-assigned this Aug 27, 2025
Copy link

changeset-bot bot commented Aug 27, 2025

⚠️ No Changeset found

Latest commit: 17317b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dobrac dobrac changed the title add template migration to CLI feat: add template migration to CLI Aug 28, 2025
@dobrac dobrac added the feature New feature or request label Aug 28, 2025
Base automatically changed from merge-templates-sdk-with-e2b-sdk-e2b-2939 to main September 5, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants