Skip to content

Commit 4579d91

Browse files
authored
feat(blueprint): support blueprint create metadata (#141)
## Description upport blueprint create metadata **Note:** PR titles should follow [Conventional Commits](https://www.conventionalcommits.org/) format (e.g., `feat(devbox): add support for custom env vars` or `fix(snapshot): resolve pagination issue`) as they are used for automatic release notes generation. ## Type of Change <!-- Mark the relevant option with an 'x' --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test updates ## Related Issues <!-- Link to related issues using #issue-number --> Closes # ## Changes Made <!-- Describe the changes in detail --> ## Testing <!-- Describe how you tested your changes --> - [ ] I have tested locally - [ ] I have added/updated tests - [ ] All existing tests pass ## Checklist - [ ] My code follows the code style of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published ## Screenshots (if applicable) <!-- Add screenshots to help explain your changes --> ## Additional Notes <!-- Any additional information that reviewers should know -->
1 parent f6be8d7 commit 4579d91

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/commands/blueprint/create.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,25 @@ interface CreateBlueprintOptions {
1616
availablePorts?: string[];
1717
root?: boolean;
1818
user?: string;
19+
metadata?: string[];
1920
output?: string;
2021
}
2122

23+
// Parse metadata from key=value format
24+
function parseMetadata(metadata: string[]): Record<string, string> {
25+
const result: Record<string, string> = {};
26+
for (const item of metadata) {
27+
const eqIndex = item.indexOf("=");
28+
if (eqIndex === -1) {
29+
throw new Error(`Invalid metadata format: ${item}. Expected key=value`);
30+
}
31+
const key = item.substring(0, eqIndex);
32+
const value = item.substring(eqIndex + 1);
33+
result[key] = value;
34+
}
35+
return result;
36+
}
37+
2238
export async function createBlueprint(options: CreateBlueprintOptions) {
2339
try {
2440
const client = getClient();
@@ -60,13 +76,19 @@ export async function createBlueprint(options: CreateBlueprintOptions) {
6076
launchParameters.user_parameters = userParameters;
6177
}
6278

79+
// Parse metadata if provided
80+
const metadata = options.metadata
81+
? parseMetadata(options.metadata)
82+
: undefined;
83+
6384
const blueprint = await client.blueprints.create({
6485
name: options.name,
6586
dockerfile: dockerfileContents,
6687
system_setup_commands: options.systemSetupCommands,
6788
launch_parameters: launchParameters as Parameters<
6889
typeof client.blueprints.create
6990
>[0]["launch_parameters"],
91+
metadata,
7092
});
7193

7294
// Default: output JSON

src/commands/blueprint/from-dockerfile.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,27 @@ interface FromDockerfileOptions {
2424
availablePorts?: string[];
2525
root?: boolean;
2626
user?: string;
27+
metadata?: string[];
2728
ttl?: string;
2829
noWait?: boolean;
2930
output?: string;
3031
}
3132

33+
// Parse metadata from key=value format
34+
function parseMetadata(metadata: string[]): Record<string, string> {
35+
const result: Record<string, string> = {};
36+
for (const item of metadata) {
37+
const eqIndex = item.indexOf("=");
38+
if (eqIndex === -1) {
39+
throw new Error(`Invalid metadata format: ${item}. Expected key=value`);
40+
}
41+
const key = item.substring(0, eqIndex);
42+
const value = item.substring(eqIndex + 1);
43+
result[key] = value;
44+
}
45+
return result;
46+
}
47+
3248
// Helper to check if we should show progress
3349
function shouldShowProgress(options: FromDockerfileOptions): boolean {
3450
return !options.output || options.output === "text";
@@ -161,6 +177,11 @@ export async function createBlueprintFromDockerfile(
161177
logProgress(`\n⏳ [2/3] Creating blueprint...`, options);
162178
const createStart = Date.now();
163179

180+
// Parse metadata if provided
181+
const metadata = options.metadata
182+
? parseMetadata(options.metadata)
183+
: undefined;
184+
164185
const createParams: BlueprintCreateParams = {
165186
name: options.name,
166187
dockerfile: dockerfileContents,
@@ -171,6 +192,7 @@ export async function createBlueprintFromDockerfile(
171192
type: "object",
172193
object_id: storageObject.id,
173194
},
195+
metadata,
174196
};
175197

176198
const blueprintResponse = await client.blueprints.create(createParams);

src/utils/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ export function createProgram(): Command {
462462
.option("--available-ports <ports...>", "Available ports")
463463
.option("--root", "Run as root")
464464
.option("--user <user:uid>", "Run as this user (format: username:uid)")
465+
.option("--metadata <tags...>", "Metadata tags (format: key=value)")
465466
.option(
466467
"-o, --output [format]",
467468
"Output format: text|json|yaml (default: json)",
@@ -552,6 +553,7 @@ export function createProgram(): Command {
552553
.option("--available-ports <ports...>", "Available ports")
553554
.option("--root", "Run as root")
554555
.option("--user <user:uid>", "Run as this user (format: username:uid)")
556+
.option("--metadata <tags...>", "Metadata tags (format: key=value)")
555557
.option(
556558
"--ttl <seconds>",
557559
"TTL in seconds for the build context object (default: 3600)",

0 commit comments

Comments
 (0)