Skip to content

Commit

Permalink
Explicitly mention Docker commands when building template (#586)
Browse files Browse the repository at this point in the history
This PR improves CLI messaging when building sandbox templates. Now, the
used Docker commands are explicitly logged to the user like this:

```
Building docker image with the following command:
docker build . \ # <--- This log is new
   -f e2b.Dockerfile \
   --pull --platform linux/amd64 \
   -t docker.e2b.dev/e2b/custom-envs/vqwjjtzwfi59d1cwww1k:ec8a819a-9666-45df-997b-e181b9fe4224 

[+] Building 0.7s (5/5) FINISHED                                                                              docker:desktop-linux
 => [internal] load build definition from e2b.Dockerfile                                                                      0.0s
 => => transferring dockerfile: 149B                                                                                          0.0s
 => [internal] load metadata for docker.io/library/ubuntu:22.04 
```
and
```
Pushing docker image with the following command:
docker push docker.e2b.dev/e2b/custom-envs/vqwjjtzwfi59d1cwww1k:ec8a819a-9666-45df-997b-e181b9fe4224 # <--- This log is new

The push refers to repository [docker.e2b.dev/e2b/custom-envs/vqwjjtzwfi59d1cwww1k]
```

so the user can potentially debug some issues on their own.
  • Loading branch information
mlejva authored Feb 21, 2025
2 parents 32e0b03 + cb6f762 commit cd4880e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-grapes-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/cli': minor
---

Explicitly mention Docker commands when building template
51 changes: 26 additions & 25 deletions packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ async function triggerTemplateBuild(templateID: string, buildID: string) {
for (let i = 0; i < maxRetries; i++) {
try {
res = await client.api.POST(
'/templates/{templateID}/builds/{buildID}',
{
params: {
path: {
templateID,
buildID,
},
'/templates/{templateID}/builds/{buildID}',
{
params: {
path: {
templateID,
buildID,
},
}
},
}
)

break
Expand Down Expand Up @@ -350,14 +350,16 @@ export const buildCommand = new commander.Command('build')
}
process.stdout.write('\n')

console.log('Building docker image...')
const cmd = `docker build . -f ${dockerfileRelativePath} --pull --platform linux/amd64 -t docker.${
connectionConfig.domain
}/e2b/custom-envs/${templateID}:${template.buildID} ${Object.entries(
const cmd = `docker build . \\
-f ${dockerfileRelativePath} \\
--pull --platform linux/amd64 \\
-t docker.${connectionConfig.domain}/e2b/custom-envs/${templateID}:${template.buildID} ${Object.entries(
dockerBuildArgs
)
.map(([key, value]) => `--build-arg="${key}=${value}"`)
.join(' ')}`
.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',
cwd: root,
Expand All @@ -366,12 +368,13 @@ export const buildCommand = new commander.Command('build')
DOCKER_CLI_HINTS: 'false',
},
})
console.log('Docker image built.\n')
console.log('> Docker image built.\n')

console.log('Pushing docker image...')
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`)
try {
child_process.execSync(
`docker push docker.${connectionConfig.domain}/e2b/custom-envs/${templateID}:${template.buildID}`,
pushCmd,
{
stdio: 'inherit',
cwd: root,
Expand All @@ -386,13 +389,13 @@ export const buildCommand = new commander.Command('build')
root
)
}
console.log('Docker image pushed.\n')
console.log('> Docker image pushed.\n')

console.log('Triggering build...')
await triggerBuild(templateID, template.buildID)

console.log(
`Triggered build for the sandbox template ${asFormattedSandboxTemplate(
`> Triggered build for the sandbox template ${asFormattedSandboxTemplate(
template
)} `
)
Expand Down Expand Up @@ -443,16 +446,14 @@ 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

0 comments on commit cd4880e

Please sign in to comment.