Skip to content
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

chore: update readme #9

Merged
merged 5 commits into from
Dec 20, 2024
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: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ CodeSandbox SDK enables you to programmatically spin up development environments

Under the hood, the SDK uses the microVM infrastructure of CodeSandbox to spin up sandboxes. It supports:

- Starting fresh VMs within 4 seconds
- Snapshotting/restoring VMs (checkpointing) at any point in time
- With snapshot restore times of less than 2 seconds
- Cloning VMs within 3 seconds
- With snapshot restore times within 1 second
- Cloning VMs & Snapshots within 2 seconds
- Source control (git, GitHub, CodeSandbox SCM)
- Running any Dockerfile

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codesandbox/sdk",
"version": "0.0.7",
"version": "0.0.9",
"description": "The CodeSandbox SDK",
"author": "CodeSandbox",
"license": "MIT",
Expand Down
35 changes: 6 additions & 29 deletions src/bin/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { hashDirectory } from "../utils/hash";

export type BuildCommandArgs = {
path: string;
force?: boolean;
ipCountry?: string;
fromSandbox?: string;
skipFiles?: boolean;
Expand All @@ -31,12 +30,6 @@ export const buildCommand: yargs.CommandModule<
"Build an efficient memory snapshot from a directory. This snapshot can be used to create sandboxes quickly.",
builder: (yargs: yargs.Argv) =>
yargs
.option("force", {
alias: "f",
describe:
"Force the creation of a new sandbox, normally a sandbox is reused if it already exists for the given folder (if the files are the same)",
type: "boolean",
})
.option("ip-country", {
describe:
"Cluster closest to this country to create the snapshot in, this ensures that sandboxes created of this snapshot will be created in the same cluster",
Expand Down Expand Up @@ -101,7 +94,7 @@ export const buildCommand: yargs.CommandModule<
alreadyExists: true,
sandboxId: argv.fromSandbox,
}
: await getOrCreateSandbox(apiClient, tag, argv.force);
: await createSandbox(apiClient, tag);

if (alreadyExists && !argv.fromSandbox) {
spinner.succeed("Sandbox snapshot has been created before:");
Expand Down Expand Up @@ -276,7 +269,9 @@ export const buildCommand: yargs.CommandModule<

spinner.succeed("All ports are open");
} else {
spinner.succeed("No ports to open, waiting 5 seconds for tasks to run...");
spinner.succeed(
"No ports to open, waiting 5 seconds for tasks to run..."
);
await new Promise((resolve) => setTimeout(resolve, 5000));
}

Expand All @@ -297,31 +292,13 @@ export const buildCommand: yargs.CommandModule<
},
};

async function getOrCreateSandbox(
async function createSandbox(
apiClient: Client,
shaTag: string,
force = false
shaTag: string
): Promise<{
alreadyExists: boolean;
sandboxId: string;
}> {
if (!force) {
const res = handleResponse(
await sandboxList({
query: {
page_size: 1,
tags: shaTag,
},
client: apiClient,
}),
"Failed to get sandboxes from API"
);

if (res.sandboxes.length > 0) {
return { alreadyExists: true, sandboxId: res.sandboxes[0].id };
}
}

const sandbox = handleResponse(
await sandboxCreate({
client: apiClient,
Expand Down
1 change: 0 additions & 1 deletion src/sandbox-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export class SandboxClient {
});

const sandbox = handleResponse(result, "Failed to create sandbox");
console.log(sandbox);

return this.connectToSandbox(sandbox.id, () => {
if (sandbox.start_response) {
Expand Down