-
Notifications
You must be signed in to change notification settings - Fork 7
fix(sandbox): add sandbox to the root command #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@bunny.net/sandbox": patch | ||
| "@bunny.net/cli": patch | ||
| --- | ||
|
|
||
| Sandbox is now visible on the CLI root help and landing page, with create examples in the README and root help. The backing Magic Containers app is now named `sandbox-<name>` so sandboxes are recognizable in the MC dashboard; default generated sandbox names dropped their `sandbox-` prefix accordingly. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ type McClient = ReturnType<typeof createMcClient>; | |
|
|
||
| const DEFAULT_REGION = "AMS"; | ||
| const DEFAULT_VOLUME_GB = 10; | ||
| /** Prefix that marks the backing MC app as sandbox-owned. */ | ||
| const APP_NAME_PREFIX = "sandbox-"; | ||
| const SSH_REACHABLE_TIMEOUT_MS = 120_000; | ||
| const DEFAULT_IMAGE = { | ||
| registryId: "1156", | ||
|
|
@@ -92,7 +94,7 @@ export class Sandbox { | |
| const agentToken = generateToken(); | ||
|
|
||
| const appId = await createApp(client, { | ||
| name, | ||
| name: appNameFor(name), | ||
| region: options.region ?? DEFAULT_REGION, | ||
| agentToken, | ||
| volumeSize: options.volumeSize ?? DEFAULT_VOLUME_GB, | ||
|
|
@@ -148,7 +150,8 @@ export class Sandbox { | |
| "Could not recover sandbox credentials from the app.", | ||
| ); | ||
| } | ||
| const name = (app as { name?: string }).name ?? options.appId; | ||
| const appName = (app as { name?: string }).name; | ||
| const name = appName ? sandboxNameFor(appName) : options.appId; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
|
|
||
| return new Sandbox( | ||
| { | ||
|
|
@@ -448,5 +451,17 @@ function generateToken(): string { | |
| } | ||
|
|
||
| function generateName(): string { | ||
| return `sandbox-${randomBytes(4).toString("hex")}`; | ||
| return randomBytes(4).toString("hex"); | ||
| } | ||
|
|
||
| /** MC app name for a sandbox: always `sandbox-<name>`. */ | ||
| export function appNameFor(name: string): string { | ||
| return `${APP_NAME_PREFIX}${name}`; | ||
| } | ||
|
|
||
| /** Recover the sandbox name from an MC app name by stripping one prefix. */ | ||
| export function sandboxNameFor(appName: string): string { | ||
| return appName.startsWith(APP_NAME_PREFIX) | ||
| ? appName.slice(APP_NAME_PREFIX.length) | ||
| : appName; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When callers pass a sandbox name between 93 and 100 characters, the name previously fit the MC app schema, but adding
sandbox-here sends a value over the 100-character API limit (AddApplicationRequest.nameinpackages/openapi-client/specs/magic-containers.jsoncaps it at 100). This makes otherwise validSandbox.create({ name })calls fail at create time; validate the user-facing sandbox name against the reduced limit or otherwise account for the prefix before callingcreateApp.Useful? React with 👍 / 👎.