Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

79 lines
2.8 KiB
TypeScript

#!/usr/bin/env bun
/**
* Builds the E2B sandbox template used by Create PR (including its optional
* Babysit continuation) and Review Code.
*
* Layers the `pi` CLI, its required Node version, and git onto E2B's
* `code-interpreter` base. The cloud backend runs `pi` and git inside this
* sandbox, so both must resolve on PATH.
*
* Usage:
* E2B_API_KEY=... bun run apps/sim/scripts/build-pi-e2b-template.ts [--name <name>] [--no-cache]
*
* After it builds, set the printed value in the Sim app's .env:
* E2B_PI_TEMPLATE_ID=<name>
* `Sandbox.create` resolves by template name, so use the name (not the ID).
*/
import { defaultBuildLogger, Template, waitForTimeout } from '@e2b/code-interpreter'
import {
PI_APT,
PI_BUN_VERSION_ASSERT,
PI_GLOBAL_NPM_PACKAGES,
PI_NODE_MAJOR,
PI_NODE_VERSION_ASSERT,
PI_SANDBOX_CPU_COUNT,
PI_SANDBOX_MEMORY_MB,
} from '@/scripts/pi-sandbox-packages'
const DEFAULT_TEMPLATE_NAME = 'sim-pi'
/** Pi 0.80 requires Node >=22.19; E2B's code-interpreter base currently ships Node 20. */
const INSTALL_NODE_COMMAND = `curl -fsSL https://deb.nodesource.com/setup_${PI_NODE_MAJOR}.x | bash - && apt-get install -y nodejs && ${PI_NODE_VERSION_ASSERT}`
/** Pi uses the command and filesystem APIs, so the inherited Jupyter service is unnecessary. */
const START_COMMAND = 'sleep infinity'
const piTemplate = Template()
.fromTemplate('code-interpreter-v1')
.runCmd(INSTALL_NODE_COMMAND, { user: 'root' })
.aptInstall([...PI_APT])
.npmInstall([...PI_GLOBAL_NPM_PACKAGES], { g: true })
.runCmd(PI_BUN_VERSION_ASSERT, { user: 'root' })
.setStartCmd(START_COMMAND, waitForTimeout(1_000))
async function main() {
if (!process.env.E2B_API_KEY) {
console.error('E2B_API_KEY is required')
process.exit(1)
}
const args = process.argv.slice(2)
const nameIdx = args.indexOf('--name')
const templateName = nameIdx !== -1 ? args[nameIdx + 1] : DEFAULT_TEMPLATE_NAME
const skipCache = args.includes('--no-cache')
console.log(`Building Pi E2B template: ${templateName}`)
console.log(`Resources: ${PI_SANDBOX_CPU_COUNT} vCPU / ${PI_SANDBOX_MEMORY_MB} MB`)
console.log(skipCache ? 'Cache: disabled\n' : 'Cache: enabled\n')
// Resources are fixed at build time — E2B has no per-`Sandbox.create` override —
// so this template's sizing applies to Create PR, Review Code, and Babysit
// alike, and changing it means rebuilding rather than redeploying the app.
const result = await Template.build(piTemplate, templateName, {
cpuCount: PI_SANDBOX_CPU_COUNT,
memoryMB: PI_SANDBOX_MEMORY_MB,
onBuildLogs: defaultBuildLogger(),
...(skipCache ? { skipCache: true } : {}),
})
console.log(`\nDone. Template ID: ${result.templateId}`)
console.log(`Set in .env: E2B_PI_TEMPLATE_ID=${templateName}`)
}
main().catch((error) => {
console.error('Build failed:', error)
process.exit(1)
})