Skip to content

Commit ae7d92c

Browse files
committed
switch to async sdk since that is perferred anyway
1 parent c68469e commit ae7d92c

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

EXAMPLES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Runnable examples live in [`examples/`](./examples).
1414
<a id="blueprint-with-build-context"></a>
1515
## Blueprint with Build Context
1616

17-
**Use case:** Create a blueprint using the object store to provide docker build context files, then verify files are copied into the image.
17+
**Use case:** Create a blueprint using the object store to provide docker build context files, then verify files are copied into the image. Uses the async SDK.
1818

19-
**Tags:** `blueprint`, `object-store`, `build-context`, `devbox`, `cleanup`
19+
**Tags:** `blueprint`, `object-store`, `build-context`, `devbox`, `cleanup`, `async`
2020

2121
### Workflow
2222
- Create a temporary directory with sample application files

examples/blueprint_with_build_context.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44
title: Blueprint with Build Context
55
slug: blueprint-with-build-context
6-
use_case: Create a blueprint using the object store to provide docker build context files, then verify files are copied into the image.
6+
use_case: Create a blueprint using the object store to provide docker build context files, then verify files are copied into the image. Uses the async SDK.
77
workflow:
88
- Create a temporary directory with sample application files
99
- Upload the directory to object storage as build context
@@ -17,6 +17,7 @@
1717
- build-context
1818
- devbox
1919
- cleanup
20+
- async
2021
prerequisites:
2122
- RUNLOOP_API_KEY
2223
run: uv run python -m examples.blueprint_with_build_context
@@ -30,7 +31,7 @@
3031
from pathlib import Path
3132
from datetime import timedelta
3233

33-
from runloop_api_client import RunloopSDK
34+
from runloop_api_client import AsyncRunloopSDK
3435
from runloop_api_client.lib.polling import PollingConfig
3536

3637
from ._harness import run_as_cli, unique_name, wrap_recipe
@@ -42,11 +43,11 @@
4243
ONE_WEEK = timedelta(weeks=1)
4344

4445

45-
def recipe(ctx: RecipeContext) -> RecipeOutput:
46+
async def recipe(ctx: RecipeContext) -> RecipeOutput:
4647
"""Create a blueprint with build context from object storage, then verify files in a devbox."""
4748
cleanup = ctx.cleanup
4849

49-
sdk = RunloopSDK()
50+
sdk = AsyncRunloopSDK()
5051

5152
# setup: create a temporary directory with sample application files to use as build context
5253
with tempfile.TemporaryDirectory() as tmp_dir:
@@ -55,15 +56,15 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
5556
(tmp_path / "config.txt").write_text("key=value")
5657

5758
# upload the build context to object storage
58-
storage_obj = sdk.storage_object.upload_from_dir(
59+
storage_obj = await sdk.storage_object.upload_from_dir(
5960
tmp_path,
6061
name=unique_name("example-build-context"),
6162
ttl=ONE_WEEK,
6263
)
6364
cleanup.add(f"storage_object:{storage_obj.id}", storage_obj.delete)
6465

6566
# create a blueprint with the build context
66-
blueprint = sdk.blueprint.create(
67+
blueprint = await sdk.blueprint.create(
6768
name=unique_name("example-blueprint-context"),
6869
dockerfile="FROM ubuntu:22.04\nWORKDIR /app\nCOPY . .",
6970
build_context=storage_obj.as_build_context(),
@@ -74,7 +75,7 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
7475
)
7576
cleanup.add(f"blueprint:{blueprint.id}", blueprint.delete)
7677

77-
devbox = blueprint.create_devbox(
78+
devbox = await blueprint.create_devbox(
7879
name=unique_name("example-devbox"),
7980
launch_parameters={
8081
"resource_size_request": "X_SMALL",
@@ -83,11 +84,11 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
8384
)
8485
cleanup.add(f"devbox:{devbox.id}", devbox.shutdown)
8586

86-
app_result = devbox.cmd.exec("cat /app/app.py")
87-
app_stdout = app_result.stdout()
87+
app_result = await devbox.cmd.exec("cat /app/app.py")
88+
app_stdout = await app_result.stdout()
8889

89-
config_result = devbox.cmd.exec("cat /app/config.txt")
90-
config_stdout = config_result.stdout()
90+
config_result = await devbox.cmd.exec("cat /app/config.txt")
91+
config_stdout = await config_result.stdout()
9192

9293
return RecipeOutput(
9394
resources_created=[

0 commit comments

Comments
 (0)