Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-candles-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/cli': patch
---

fixes an issue building templates on Windows
72 changes: 41 additions & 31 deletions packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ async function triggerTemplateBuild(templateID: string, buildID: string) {
const maxRetries = 3
for (let i = 0; i < maxRetries; i++) {
try {
res = await client.api.POST(
'/templates/{templateID}/builds/{buildID}',
{
params: {
path: {
templateID,
buildID,
},
res = await client.api.POST('/templates/{templateID}/builds/{buildID}', {
params: {
path: {
templateID,
buildID,
},
}
)
},
})

break
} catch (e) {
// If the build and push takes more than 10 minutes the connection gets automatically closed by load balancer
// and the request fails with UND_ERR_SOCKET error. In this case we just need to retry the request.
if ((e instanceof TypeError) && (((e as TypeError).cause) as any)?.code !== 'UND_ERR_SOCKET') {
if (
e instanceof TypeError &&
((e as TypeError).cause as any)?.code !== 'UND_ERR_SOCKET'
) {
console.error(e)
console.log('Retrying...')
}
Expand Down Expand Up @@ -350,15 +350,22 @@ export const buildCommand = new commander.Command('build')
}
process.stdout.write('\n')

const cmd = `docker build . \\
-f ${dockerfileRelativePath} \\
--pull --platform linux/amd64 \\
-t docker.${connectionConfig.domain}/e2b/custom-envs/${templateID}:${template.buildID} ${Object.entries(
dockerBuildArgs
const buildArgs = Object.entries(dockerBuildArgs)
.map(([key, value]) => `--build-arg "${key}=${value}"`)
.join(' ')

const cmd = [
'docker build',
`-f ${dockerfileRelativePath}`,
'--pull --platform linux/amd64',
`-t docker.${connectionConfig.domain}/e2b/custom-envs/${templateID}:${template.buildID}`,
buildArgs,
'.',
].join(' ')

console.log(
`Building docker image with the following command:\n${asBold(cmd)}\n`
)
.map(([key, value]) => `--build-arg "${key}=${value}"`)
.join(' \\ \n ')}`
console.log(`Building docker image with the following command:\n${asBold(cmd)}\n`)

child_process.execSync(cmd, {
stdio: 'inherit',
Expand All @@ -371,15 +378,16 @@ export const buildCommand = new commander.Command('build')
console.log('> Docker image built.\n')

const pushCmd = `docker push docker.${connectionConfig.domain}/e2b/custom-envs/${templateID}:${template.buildID}`
console.log(`Pushing docker image with the following command:\n${asBold(pushCmd)}\n`)
console.log(
`Pushing docker image with the following command:\n${asBold(
pushCmd
)}\n`
)
try {
child_process.execSync(
pushCmd,
{
stdio: 'inherit',
cwd: root,
}
)
child_process.execSync(pushCmd, {
stdio: 'inherit',
cwd: root,
})
} catch (err: any) {
await buildWithProxy(
userConfig,
Expand Down Expand Up @@ -446,14 +454,16 @@ async function waitForBuildFinish(
sandbox = Sandbox("${aliases?.length ? aliases[0] : template.templateID}")

# Create async sandbox
sandbox = await AsyncSandbox.create("${aliases?.length ? aliases[0] : template.templateID
}")`)
sandbox = await AsyncSandbox.create("${
aliases?.length ? aliases[0] : template.templateID
}")`)

const typescriptExample = asTypescript(`import { Sandbox } from 'e2b'

// Create sandbox
const sandbox = await Sandbox.create('${aliases?.length ? aliases[0] : template.templateID
}')`)
const sandbox = await Sandbox.create('${
aliases?.length ? aliases[0] : template.templateID
}')`)

const examplesMessage = `You can now use the template to create custom sandboxes.\nLearn more on ${asPrimary(
'https://e2b.dev/docs'
Expand Down
Loading