Skip to content
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
22 changes: 22 additions & 0 deletions src/commands/blueprint/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ interface CreateBlueprintOptions {
availablePorts?: string[];
root?: boolean;
user?: string;
metadata?: string[];
output?: string;
}

// Parse metadata from key=value format
function parseMetadata(metadata: string[]): Record<string, string> {
const result: Record<string, string> = {};
for (const item of metadata) {
const eqIndex = item.indexOf("=");
if (eqIndex === -1) {
throw new Error(`Invalid metadata format: ${item}. Expected key=value`);
}
const key = item.substring(0, eqIndex);
const value = item.substring(eqIndex + 1);
result[key] = value;
}
return result;
}

export async function createBlueprint(options: CreateBlueprintOptions) {
try {
const client = getClient();
Expand Down Expand Up @@ -60,13 +76,19 @@ export async function createBlueprint(options: CreateBlueprintOptions) {
launchParameters.user_parameters = userParameters;
}

// Parse metadata if provided
const metadata = options.metadata
? parseMetadata(options.metadata)
: undefined;

const blueprint = await client.blueprints.create({
name: options.name,
dockerfile: dockerfileContents,
system_setup_commands: options.systemSetupCommands,
launch_parameters: launchParameters as Parameters<
typeof client.blueprints.create
>[0]["launch_parameters"],
metadata,
});

// Default: output JSON
Expand Down
22 changes: 22 additions & 0 deletions src/commands/blueprint/from-dockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,27 @@ interface FromDockerfileOptions {
availablePorts?: string[];
root?: boolean;
user?: string;
metadata?: string[];
ttl?: string;
noWait?: boolean;
output?: string;
}

// Parse metadata from key=value format
function parseMetadata(metadata: string[]): Record<string, string> {
const result: Record<string, string> = {};
for (const item of metadata) {
const eqIndex = item.indexOf("=");
if (eqIndex === -1) {
throw new Error(`Invalid metadata format: ${item}. Expected key=value`);
}
const key = item.substring(0, eqIndex);
const value = item.substring(eqIndex + 1);
result[key] = value;
}
return result;
}

// Helper to check if we should show progress
function shouldShowProgress(options: FromDockerfileOptions): boolean {
return !options.output || options.output === "text";
Expand Down Expand Up @@ -161,6 +177,11 @@ export async function createBlueprintFromDockerfile(
logProgress(`\n⏳ [2/3] Creating blueprint...`, options);
const createStart = Date.now();

// Parse metadata if provided
const metadata = options.metadata
? parseMetadata(options.metadata)
: undefined;

const createParams: BlueprintCreateParams = {
name: options.name,
dockerfile: dockerfileContents,
Expand All @@ -171,6 +192,7 @@ export async function createBlueprintFromDockerfile(
type: "object",
object_id: storageObject.id,
},
metadata,
};

const blueprintResponse = await client.blueprints.create(createParams);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export function createProgram(): Command {
.option("--available-ports <ports...>", "Available ports")
.option("--root", "Run as root")
.option("--user <user:uid>", "Run as this user (format: username:uid)")
.option("--metadata <tags...>", "Metadata tags (format: key=value)")
.option(
"-o, --output [format]",
"Output format: text|json|yaml (default: json)",
Expand Down Expand Up @@ -552,6 +553,7 @@ export function createProgram(): Command {
.option("--available-ports <ports...>", "Available ports")
.option("--root", "Run as root")
.option("--user <user:uid>", "Run as this user (format: username:uid)")
.option("--metadata <tags...>", "Metadata tags (format: key=value)")
.option(
"--ttl <seconds>",
"TTL in seconds for the build context object (default: 3600)",
Expand Down
Loading