Skip to content

Commit 42849d6

Browse files
authored
feat(SDK): Build context helpers for the python clients and SDKs (#684)
* added context loader helper * added context loader helper to make it easier to add build context when creating a blueprint * added oop build context functional method wrapper * added context helpers to SDKs * made ctxt example a bit better * made this example better * refactored ignore logic to follow moby (docker project) pattern matching logic and tests * fixed some tests and broken imports * improved typing and made the ignore matching less docker-specific * added tar filter for upload_from_dir * fixed bad type * removed some dead code and standardized the ignore interface & made it a bit more ergonomic * rolled back change that made tar its own filter type -- big misunderstanding * added handling for extremely weird edge case behavior for dockerignore * added some type hints and override flags * docstring fixes and consolidation of duplicated ignore code
1 parent 663ead3 commit 42849d6

11 files changed

Lines changed: 1035 additions & 53 deletions

File tree

README-SDK.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ The `RunloopSDK` builds on top of the underlying REST client and provides a Pyth
88
- [Quickstart (synchronous)](#quickstart-synchronous)
99
- [Quickstart (asynchronous)](#quickstart-asynchronous)
1010
- [Core Concepts](#core-concepts)
11-
- [Devbox](#devbox)
12-
- [Blueprint](#blueprint)
13-
- [Snapshot](#snapshot)
14-
- [StorageObject](#storageobject)
15-
- [Mounting Storage Objects to Devboxes](#mounting-storage-objects-to-devboxes)
11+
- [RunloopSDK](#runloopsdk)
12+
- [Available Resources](#available-resources)
13+
- [Devbox](#devbox)
14+
- [Command Execution](#command-execution)
15+
- [Execution Management](#execution-management)
16+
- [Execution Results](#execution-results)
17+
- [Streaming Command Output](#streaming-command-output)
18+
- [File Operations](#file-operations)
19+
- [Network Operations](#network-operations)
20+
- [Snapshot Operations](#snapshot-operations)
21+
- [Devbox Lifecycle Management](#devbox-lifecycle-management)
22+
- [Context Manager Support](#context-manager-support)
23+
- [Blueprint](#blueprint)
24+
- [Snapshot](#snapshot)
25+
- [StorageObject](#storageobject)
26+
- [Storage Object Upload Helpers](#storage-object-upload-helpers)
27+
- [Mounting Storage Objects to Devboxes](#mounting-storage-objects-to-devboxes)
1628
- [Accessing the Underlying REST Client](#accessing-the-underlying-rest-client)
1729
- [Error Handling](#error-handling)
1830
- [Advanced Configuration](#advanced-configuration)
@@ -409,6 +421,52 @@ blueprint = runloop.blueprint.create(
409421
system_setup_commands=["pip install numpy pandas"],
410422
)
411423

424+
# Or create a blueprint with a Docker build context from a local directory
425+
from pathlib import Path
426+
from runloop_api_client.lib.context_loader import build_docker_context_tar
427+
428+
context_root = Path("./my-app")
429+
tar_bytes = build_docker_context_tar(context_root)
430+
431+
build_ctx_obj = runloop.storage_object.upload_from_bytes(
432+
data=tar_bytes,
433+
name="my-app-context.tar.gz",
434+
content_type="tgz",
435+
)
436+
437+
shared_root = Path("./shared-lib")
438+
shared_tar = build_docker_context_tar(shared_root)
439+
440+
shared_ctx_obj = runloop.storage_object.upload_from_bytes(
441+
data=shared_tar,
442+
name="shared-lib-context.tar.gz",
443+
content_type="tgz",
444+
)
445+
446+
blueprint_with_context = runloop.blueprint.create(
447+
name="my-blueprint-with-context",
448+
dockerfile="""\
449+
FROM node:22
450+
WORKDIR /usr/src/app
451+
452+
# copy using the build context from the object
453+
COPY package.json package.json
454+
COPY src src
455+
456+
# copy from named context
457+
COPY --from=shared / ./libs
458+
459+
RUN npm install --only=production
460+
CMD ["node", "src/app.js"]
461+
""",
462+
# Primary build context
463+
build_context=build_ctx_obj.as_build_context(),
464+
# Additional named build contexts (for Docker buildx-style usage)
465+
named_build_contexts={
466+
"shared": shared_ctx_obj.as_build_context(),
467+
},
468+
)
469+
412470
# Or get an existing one
413471
blueprint = runloop.blueprint.from_id(blueprint_id="bpt_123")
414472

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Helpers for `runloop_api_client`.
3+
"""

0 commit comments

Comments
 (0)