Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/e2b-dev/e2b
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva committed Nov 8, 2023
2 parents f5e2ea7 + c003378 commit aa0dcca
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
3 changes: 2 additions & 1 deletion apps/docs/src/app/sandbox/resources/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
- 512 MB RAM {{ className: 'lead' }}
- 0.5 GB free disk storage {{ className: 'lead' }}
- 24 hours max session length {{ className: 'lead' }}
- Up to 20 concurrently running sandboxes {{ className: 'lead' }}

## Pro tier (paid)
- 4 vCPU {{ className: 'lead' }}
- 4 GB RAM {{ className: 'lead' }}
- 5 GB free disk storage {{ className: 'lead' }}
- 24 hours max session length {{ className: 'lead' }}

- Running of concurrently running sandboxes to suit your needs {{ className: 'lead' }}
<Note>
Please [reach out](/getting-help) if you're interested in the Pro tier.
</Note>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@e2b/cli",
"version": "0.1.0",
"version": "0.1.2",
"description": "CLI for managing e2b sandbox templates",
"homepage": "https://e2b.dev",
"license": "MIT",
Expand Down
29 changes: 12 additions & 17 deletions packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import * as stripAnsi from 'strip-ansi'
import { wait } from 'src/utils/wait'
import { ensureAccessToken } from 'src/api'
import { getFiles, getRoot } from 'src/utils/filesystem'
import { asBold, asBuildLogs, asFormattedSandboxTemplate, asLocal, asLocalRelative, asPrimary } from 'src/utils/format'
import {
asBold,
asBuildLogs,
asFormattedSandboxTemplate,
asLocal,
asLocalRelative,
asPrimary,
} from 'src/utils/format'
import { pathOption } from 'src/options'
import { createBlobFromFiles } from 'src/docker/archive'
import { defaultDockerfileName, fallbackDockerfileName } from 'src/docker/constants'
import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config'

const templateCheckInterval = 1_000 // 1 sec
const maxBuildTime = 10 * 60 * 1_000 // 10 min

const getTemplate = e2b.withAccessToken(
e2b.api.path('/envs/{envID}/builds/{buildID}').method('get').create(),
Expand Down Expand Up @@ -164,13 +170,8 @@ async function waitForBuildFinish(
envID: string,
buildID: string,
) {
const startedAt = new Date()
let logsOffset = 0

function elapsed() {
return Date.now() - startedAt.getTime()
}

let template: Awaited<ReturnType<typeof getTemplate>> | undefined

process.stdout.write('\n')
Expand Down Expand Up @@ -213,7 +214,9 @@ async function waitForBuildFinish(
console.log(
`\n✅ Building sandbox template ${asFormattedSandboxTemplate(
template.data,
)} finished.\n`,
)} finished.\n
Now you can start creating your sandboxes from this template. You can find more here:
${asPrimary('https://e2b.dev/docs/guide/custom-sandbox')}, section ${asBold('Spawn and control your sandbox')}\n`,
)
break

Expand All @@ -227,15 +230,7 @@ async function waitForBuildFinish(
)} failed.\nCheck the logs above for more details or contact us ${asPrimary('(https://e2b.dev/docs/getting-help)')} to get help.\n`,
)
}
} while (template.data.status === 'building' && elapsed() < maxBuildTime)
// TODO: We do have another timeout for envs building in API so we probably should handle timeout only in one place
if (template.data.status === 'building' && elapsed() >= maxBuildTime) {
throw new Error(
`\n❌ Building sandbox template ${asFormattedSandboxTemplate(
template.data,
)} timed out.\nCheck the logs above for more details or contact us ${asPrimary('(https://e2b.dev/docs/getting-help)')} to get help.\n`,
)
}
} while (template.data.status === 'building')
}

function loadFile(filePath: string) {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/template/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as chalk from 'chalk'
import * as commander from 'commander'
import * as e2b from '@e2b/sdk'

import { ensureAccessToken } from 'src/api'
import { asHeadline, asPrimary } from '../../utils/format'

const listTemplates = e2b.withAccessToken(
e2b.api.path('/envs').method('get').create(),
Expand All @@ -18,14 +18,14 @@ export const listCommand = new commander.Command('list')

const templatesResponse = await listTemplates(accessToken, {})

console.log(
chalk.default.underline(chalk.default.green('Sandbox templates')),
)
console.log(asHeadline('Sandbox templates:'))


const templates = templatesResponse.data

if (!templates?.length) {
console.log('No templates found.')
console.log(`No templates found.\n
You can create a template by running ${asPrimary('e2b template build')} or visit E2B docs ${asPrimary('(https://e2b.dev/docs/guide/custom-sandbox)')} to learn more.`)
} else {
templates
.sort((a, b) => a.envID.localeCompare(b.envID))
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/template/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as commander from 'commander'

import { ensureAPIKey } from 'src/api'
import { spawnConnectedTerminal } from 'src/terminal'
import { asBold, asFormattedSandboxTemplate } from 'src/utils/format'
import { asBold, asFormattedSandboxTemplate, asPrimary } from 'src/utils/format'

export const shellCommand = new commander.Command('shell')
.description('Connect terminal to sandbox')
.argument('<id>', `Connect to sandbox specified by ${asBold('<id>')}`)
.description('Connect to the terminal in the sandbox')
.argument('<id>', `Connect to sandbox specified by ${asPrimary('template id')}`)
.alias('sh')
.action(async (id: string) => {
try {
Expand Down Expand Up @@ -35,13 +35,11 @@ async function connectSandbox({
apiKey: string;
template: Pick<e2b.components['schemas']['Environment'], 'envID'>;
}) {
const sandbox = new e2b.Sandbox({
const sandbox = await e2b.Sandbox.create({
apiKey,
id: template.envID,
})

await sandbox.open({})

if (sandbox.terminal) {
const { exited } = await spawnConnectedTerminal(
sandbox.terminal,
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ export function asLocalRelative(absolutePathInLocal?: string) {
export function asBuildLogs(content: string) {
return chalk.default.blueBright(content)
}

export function asHeadline(content: string) {
return chalk.default.underline(asPrimary(asBold(content)))
}

1 comment on commit aa0dcca

@vercel
Copy link

@vercel vercel bot commented on aa0dcca Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e2b-docs – ./apps/docs

e2b-docs.vercel.app
e2b-docs-e2b.vercel.app
e2b-docs-git-main-e2b.vercel.app

Please sign in to comment.