b9c4b16baa
## 🔄 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 ```bash # 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