Skip to content

Commit 5868d28

Browse files
committed
cp dines
1 parent 76b2b45 commit 5868d28

65 files changed

Lines changed: 1561 additions & 3497 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/commands/blueprint/create.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Create blueprint command
3+
*/
4+
5+
import { readFile } from "fs/promises";
6+
import { getClient } from "../../utils/client.js";
7+
import { output, outputError } from "../../utils/output.js";
8+
9+
interface CreateBlueprintOptions {
10+
name: string;
11+
dockerfile?: string;
12+
dockerfilePath?: string;
13+
systemSetupCommands?: string[];
14+
resources?: string;
15+
architecture?: string;
16+
availablePorts?: string[];
17+
root?: boolean;
18+
user?: string;
19+
output?: string;
20+
}
21+
22+
export async function createBlueprint(options: CreateBlueprintOptions) {
23+
try {
24+
const client = getClient();
25+
26+
// Read dockerfile from file if path is provided
27+
let dockerfileContents = options.dockerfile;
28+
if (options.dockerfilePath) {
29+
dockerfileContents = await readFile(options.dockerfilePath, "utf-8");
30+
}
31+
32+
// Parse user parameters
33+
let userParameters = undefined;
34+
if (options.user && options.root) {
35+
outputError("Only one of --user or --root can be specified");
36+
} else if (options.user) {
37+
const [username, uid] = options.user.split(":");
38+
if (!username || !uid) {
39+
outputError("User must be in format 'username:uid'");
40+
}
41+
userParameters = { username, uid: parseInt(uid) };
42+
} else if (options.root) {
43+
userParameters = { username: "root", uid: 0 };
44+
}
45+
46+
// Build launch parameters
47+
const launchParameters: Record<string, unknown> = {};
48+
if (options.resources) {
49+
launchParameters.resource_size_request = options.resources;
50+
}
51+
if (options.architecture) {
52+
launchParameters.architecture = options.architecture;
53+
}
54+
if (options.availablePorts) {
55+
launchParameters.available_ports = options.availablePorts.map((port) => parseInt(port, 10));
56+
}
57+
if (userParameters) {
58+
launchParameters.user_parameters = userParameters;
59+
}
60+
61+
const blueprint = await client.blueprints.create({
62+
name: options.name,
63+
dockerfile: dockerfileContents,
64+
system_setup_commands: options.systemSetupCommands,
65+
launch_parameters: launchParameters as Parameters<typeof client.blueprints.create>[0]["launch_parameters"],
66+
});
67+
68+
// Default: just output the ID for easy scripting
69+
if (!options.output || options.output === "text") {
70+
console.log(blueprint.id);
71+
} else {
72+
output(blueprint, { format: options.output, defaultFormat: "json" });
73+
}
74+
} catch (error) {
75+
outputError("Failed to create blueprint", error);
76+
}
77+
}

src/commands/blueprint/create.tsx

Lines changed: 0 additions & 183 deletions
This file was deleted.

src/commands/blueprint/get.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get blueprint details command
3+
*/
4+
5+
import { getClient } from "../../utils/client.js";
6+
import { output, outputError } from "../../utils/output.js";
7+
8+
interface GetBlueprintOptions {
9+
id: string;
10+
output?: string;
11+
}
12+
13+
export async function getBlueprint(options: GetBlueprintOptions) {
14+
try {
15+
const client = getClient();
16+
const blueprint = await client.blueprints.retrieve(options.id);
17+
output(blueprint, { format: options.output, defaultFormat: "json" });
18+
} catch (error) {
19+
outputError("Failed to get blueprint", error);
20+
}
21+
}
22+

src/commands/blueprint/get.tsx

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)