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
24 changes: 22 additions & 2 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './sdk/index';
import type * as Core from './core';
import { Runloop, type ClientOptions } from './index';
import { Devbox } from './sdk/devbox';
import { Blueprint } from './sdk/blueprint';
import { Blueprint, type CreateParams as BlueprintCreateParams } from './sdk/blueprint';
import { Snapshot } from './sdk/snapshot';
import { StorageObject } from './sdk/storage-object';

Expand All @@ -13,7 +13,7 @@ import type {
DevboxView,
DevboxListDiskSnapshotsParams,
} from './resources/devboxes/devboxes';
import type { BlueprintCreateParams, BlueprintListParams } from './resources/blueprints';
import type { BlueprintListParams } from './resources/blueprints';
import type { ObjectCreateParams, ObjectListParams } from './resources/objects';
import { PollingOptions } from './lib/polling';

Expand Down Expand Up @@ -283,6 +283,26 @@ export class DevboxOps {
* });
* const devbox = await sdk.devbox.createFromBlueprintId(blueprint.id, { name: 'my-devbox' });
* ```
*
* To use a local directory as a build context, use an object.
*
* @example
* ```typescript
* const sdk = new RunloopSDK();
* const obj = await sdk.storageObject.uploadFromDir(
* './',
Comment thread
adam-rl marked this conversation as resolved.
* {
* name: 'build-context',
* ttl_ms: 3600000, // 1 hour
* }
* );
* const blueprint = await sdk.blueprint.create({
* name: 'my-blueprint-with-context',
* dockerfile: `FROM ubuntu:22.04
* COPY . .`,
* build_context: obj,
* });
* ```
*/
export class BlueprintOps {
/**
Expand Down
23 changes: 19 additions & 4 deletions src/sdk/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import type {
import type { DevboxCreateParams, DevboxView } from '../resources/devboxes/devboxes';
import type { PollingOptions } from '../lib/polling';
import { Devbox } from './devbox';
import { StorageObject } from './storage-object';

export type CreateParams = Omit<BlueprintCreateParams, 'build_context'> & {
/**
* A build context to attach to the Blueprint build.
* Enables the use of `COPY` Dockerfile directives.
*/
build_context?: StorageObject | BlueprintCreateParams.BuildContext | null;
};

/**
* Object-oriented interface for working with Blueprints.
* ```
*/
export class Blueprint {
private client: Runloop;
Expand All @@ -30,18 +38,25 @@ export class Blueprint {
* @private
*
* @param {Runloop} client - The Runloop client instance
* @param {BlueprintCreateParams} params - Parameters for creating the blueprint
* @param {CreateParams} params - Parameters for creating the blueprint
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<BlueprintView>> }} [options] - Request options with optional polling configuration
* @returns {Promise<Blueprint>} A {@link Blueprint} instance with completed build
*/
static async create(
client: Runloop,
params: BlueprintCreateParams,
params: CreateParams,
options?: Core.RequestOptions & {
polling?: Partial<PollingOptions<BlueprintView>>;
},
): Promise<Blueprint> {
const blueprintData = await client.blueprints.createAndAwaitBuildCompleted(params, options);
let rawParams = { ...params };
if (params.build_context instanceof StorageObject) {
rawParams.build_context = { type: 'object', object_id: params.build_context.id };
}
const blueprintData = await client.blueprints.createAndAwaitBuildCompleted(
rawParams as BlueprintCreateParams,
options,
);
return new Blueprint(client, blueprintData.id);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/objects/blueprint.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Blueprint } from '../../src/sdk/blueprint';
import { Devbox } from '../../src/sdk/devbox';
import type { BlueprintView, BlueprintBuildLogsListView } from '../../src/resources/blueprints';
import { StorageObject } from '@runloop/api-client/sdk';

// Mock the Runloop client
jest.mock('../../src/index');
Expand Down Expand Up @@ -125,6 +126,29 @@ describe('Blueprint (New API)', () => {
undefined,
);
});

it('should support convenience object build_context blueprint configuration', async () => {
mockClient.blueprints.createAndAwaitBuildCompleted.mockResolvedValue(mockBlueprintData);

const obj = StorageObject.fromId(mockClient, 'obj_foo');

await Blueprint.create(mockClient, {
name: 'build-context-object-blueprint',
dockerfile: 'FROM ubuntu:22.04',
build_context: obj,
metadata: { version: '1.0' },
});

expect(mockClient.blueprints.createAndAwaitBuildCompleted).toHaveBeenCalledWith(
{
name: 'build-context-object-blueprint',
dockerfile: 'FROM ubuntu:22.04',
build_context: { type: 'object', object_id: 'obj_foo' },
metadata: { version: '1.0' },
},
undefined,
);
});
});

describe('fromId', () => {
Expand Down
Loading