Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

CLI migrate: Rename old template files no longer needed (#991)

Mish Ushakovad194b4f4a04
diff --git a/.changeset/thin-suits-arrive.md b/.changeset/thin-suits-arrive.md
new file mode 100644
index 000000000..783c67baf
--- /dev/null
+++ b/.changeset/thin-suits-arrive.md
@@ -0,0 +1,5 @@
+---
+'@e2b/cli': patch
+---
+
+rename e2b.toml and Dockerfile to e2b.toml.old and Dockerfile.old on migrate
diff --git a/packages/cli/src/commands/template/migrate.ts b/packages/cli/src/commands/template/migrate.ts
index 51a7f2fa2..238c72f9d 100644
--- a/packages/cli/src/commands/template/migrate.ts
+++ b/packages/cli/src/commands/template/migrate.ts
@@ -21,7 +21,7 @@ import {
async function migrateToLanguage(
root: string,
config: E2BConfig,
- dockerfilePath: string,
+ dockerfileContent: string,
language: Language
): Promise<void> {
// Initialize template with file context
@@ -29,8 +29,6 @@ async function migrateToLanguage(
fileContextPath: root,
})
- const { dockerfileContent } = getDockerfile(root, dockerfilePath)
-
// Parse Dockerfile using SDK
let baseTemplate: TemplateBuilder
try {
@@ -124,6 +122,9 @@ export const migrateCommand = new commander.Command('migrate')
const root = getRoot(opts.path)
const configPath = getConfigPath(root, opts.config)
+ const { dockerfileContent, dockerfilePath, dockerfileRelativePath } =
+ getDockerfile(root, opts.dockerfile)
+
let config: E2BConfig = {
template_id: 'name-your-template',
dockerfile: defaultDockerfileName,
@@ -140,10 +141,6 @@ export const migrateCommand = new commander.Command('migrate')
)
}
- // Determine Dockerfile path
- const dockerfilePath =
- opts.dockerfile || config.dockerfile || defaultDockerfileName
-
// Determine target language
let language: Language
if (opts.language) {
@@ -176,10 +173,43 @@ export const migrateCommand = new commander.Command('migrate')
}
// Perform migration
- await migrateToLanguage(root, config, dockerfilePath, language)
+ await migrateToLanguage(root, config, dockerfileContent, language)
+
+ // Rename old files to .old extensions
+ const oldFilesRenamed: { oldPath: string; newPath: string }[] = []
+
+ // Rename Dockerfile if it exists
+ if (fs.existsSync(dockerfilePath)) {
+ const oldDockerfilePath = `${dockerfilePath}.old`
+ fs.renameSync(dockerfilePath, oldDockerfilePath)
+ oldFilesRenamed.push({
+ oldPath: dockerfileRelativePath,
+ newPath: path.relative(root, oldDockerfilePath),
+ })
+ }
+
+ // Rename e2b.toml if it exists
+ if (fs.existsSync(configPath)) {
+ const oldConfigPath = `${configPath}.old`
+ fs.renameSync(configPath, oldConfigPath)
+ oldFilesRenamed.push({
+ oldPath: path.relative(root, configPath),
+ newPath: path.relative(root, oldConfigPath),
+ })
+ }
+
+ if (oldFilesRenamed.length > 0) {
+ console.log('\n📁 Old template files no longer needed:')
+ oldFilesRenamed.forEach((file) => {
+ console.log(
+ ` ${asLocalRelative(file.oldPath)} → ${asLocalRelative(file.newPath)}`
+ )
+ })
+ }
console.log('\n🎉 Migration completed successfully!')
- console.log('\nYou can now build your template using:')
+
+ console.log('\n🔨 You can now build your template using:')
if (language === Language.TypeScript) {
console.log(
` ${asPrimary('npx tsx build.dev.ts')} (for development)`
diff --git a/packages/cli/tests/commands/template/migrate.test.ts b/packages/cli/tests/commands/template/migrate.test.ts
index 5a7f36d33..227cffb96 100644
--- a/packages/cli/tests/commands/template/migrate.test.ts
+++ b/packages/cli/tests/commands/template/migrate.test.ts
@@ -125,6 +125,40 @@ describe('Template Migration', () => {
'utf-8'
)
expect(buildProdFile.trim()).toEqual(expectedBuildProd.trim())
+
+ // Check that old files are renamed to .old extensions
+ const oldDockerfilePath = path.join(testDir, 'e2b.Dockerfile.old')
+ const oldConfigPath = path.join(testDir, 'e2b.toml.old')
+
+ expect(
+ await fs
+ .access(oldDockerfilePath)
+ .then(() => true)
+ .catch(() => false)
+ ).toBe(true)
+ expect(
+ await fs
+ .access(oldConfigPath)
+ .then(() => true)
+ .catch(() => false)
+ ).toBe(true)
+
+ // Verify original files no longer exist
+ const originalDockerfilePath = path.join(testDir, 'e2b.Dockerfile')
+ const originalConfigPath = path.join(testDir, 'e2b.toml')
+
+ expect(
+ await fs
+ .access(originalDockerfilePath)
+ .then(() => true)
+ .catch(() => false)
+ ).toBe(false)
+ expect(
+ await fs
+ .access(originalConfigPath)
+ .then(() => true)
+ .catch(() => false)
+ ).toBe(false)
}
async function copyFixtureFiles(fixtureDir: string, targetDir: string) {