|
| 1 | +/** |
| 2 | + * Build the shared agent blueprint for all examples. |
| 3 | + * |
| 4 | + * Usage: |
| 5 | + * bun run build-blueprint.ts |
| 6 | + * |
| 7 | + * Environment: |
| 8 | + * RUNLOOP_API_KEY - Required Runloop API key |
| 9 | + * RUNLOOP_BASE_URL - Optional API base URL override |
| 10 | + */ |
| 11 | + |
| 12 | +import { RunloopSDK } from "@runloop/api-client"; |
| 13 | +import { readFileSync } from "fs"; |
| 14 | +import { dirname, join } from "path"; |
| 15 | +import { fileURLToPath } from "url"; |
| 16 | + |
| 17 | +export const BLUEPRINT_NAME = "axon-agents"; |
| 18 | + |
| 19 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 20 | + |
| 21 | +async function main() { |
| 22 | + const apiKey = process.env.RUNLOOP_API_KEY; |
| 23 | + if (!apiKey) { |
| 24 | + console.error("RUNLOOP_API_KEY not set"); |
| 25 | + process.exit(1); |
| 26 | + } |
| 27 | + |
| 28 | + const baseUrl = process.env.RUNLOOP_BASE_URL; |
| 29 | + const sdk = new RunloopSDK({ |
| 30 | + bearerToken: apiKey, |
| 31 | + ...(baseUrl ? { baseURL: baseUrl } : {}), |
| 32 | + }); |
| 33 | + |
| 34 | + const dockerfilePath = join(__dirname, "Dockerfile"); |
| 35 | + const dockerfile = readFileSync(dockerfilePath, "utf-8"); |
| 36 | + |
| 37 | + console.log(`Building blueprint "${BLUEPRINT_NAME}"...`); |
| 38 | + console.log("Dockerfile contents:"); |
| 39 | + console.log("---"); |
| 40 | + console.log(dockerfile); |
| 41 | + console.log("---"); |
| 42 | + |
| 43 | + const blueprint = await sdk.blueprint.create({ |
| 44 | + name: BLUEPRINT_NAME, |
| 45 | + dockerfile, |
| 46 | + launch_parameters: { |
| 47 | + user_parameters: { |
| 48 | + uid: 1000, |
| 49 | + username: "user", |
| 50 | + }, |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + console.log(`Blueprint created: ${blueprint.id}`); |
| 55 | + |
| 56 | + // Get the final status |
| 57 | + const info = await blueprint.getInfo(); |
| 58 | + console.log(`Name: ${info.name}`); |
| 59 | + console.log(`Status: ${info.status}`); |
| 60 | + |
| 61 | + if (info.status === "build_complete") { |
| 62 | + console.log("\nBlueprint build complete."); |
| 63 | + console.log(`Use blueprint_name: "${BLUEPRINT_NAME}" in devbox.create()`); |
| 64 | + } else { |
| 65 | + console.error(`\nUnexpected blueprint status: ${info.status}`); |
| 66 | + const logs = await blueprint.logs(); |
| 67 | + if (logs.logs.length > 0) { |
| 68 | + console.error("Build logs:"); |
| 69 | + for (const entry of logs.logs) { |
| 70 | + console.error(`[${entry.level}] ${entry.message}`); |
| 71 | + } |
| 72 | + } |
| 73 | + process.exit(1); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +main().catch((err) => { |
| 78 | + console.error("Error:", err); |
| 79 | + process.exit(1); |
| 80 | +}); |
0 commit comments