diff --git a/scripts/run-config/add-serverless.ts b/scripts/run-config/add-serverless.ts new file mode 100755 index 0000000000..8556009bf7 --- /dev/null +++ b/scripts/run-config/add-serverless.ts @@ -0,0 +1,60 @@ +#!/usr/bin/env tsx + +import * as readline from "readline/promises"; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const rivetToken = process.env.RIVET_TOKEN; +if (!rivetToken) { + console.error("Error: RIVET_TOKEN environment variable is not set"); + process.exit(1); +} + +const endpoint = + process.env.RIVET_ENDPOINT || + (await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) || + "https://api.rivet.gg"; +const namespace = + (await rl.question("Namespace (default: default): ")) || "default"; +const runnerName = + (await rl.question("Runner name (default: serverless): ")) || "serverless"; +const serverlessUrl = + (await rl.question( + "Serverless URL (default: http://localhost:8080/api/start): ", + )) || "http://localhost:8080/api/start"; + +rl.close(); + +const response = await fetch( + `${endpoint}/runner-configs/${runnerName}?namespace=${namespace}`, + { + method: "PUT", + headers: { + Authorization: `Bearer ${rivetToken}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + serverless: { + url: serverlessUrl, + headers: {}, + runners_margin: 1, + min_runners: 1, + max_runners: 3, + slots_per_runner: 100, + request_lifespan: 15 * 60, + }, + }), + }, +); + +if (!response.ok) { + console.error(`Error: ${response.status} ${response.statusText}`); + console.error(await response.text()); + process.exit(1); +} + +console.log("✅ Successfully configured serverless runner!"); + diff --git a/scripts/run-config/delete-run-config.ts b/scripts/run-config/delete-run-config.ts new file mode 100755 index 0000000000..b2ab310092 --- /dev/null +++ b/scripts/run-config/delete-run-config.ts @@ -0,0 +1,47 @@ +#!/usr/bin/env tsx + +import * as readline from "readline/promises"; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const rivetToken = process.env.RIVET_TOKEN; +if (!rivetToken) { + console.error("Error: RIVET_TOKEN environment variable is not set"); + process.exit(1); +} + +const endpoint = + process.env.RIVET_ENDPOINT || + (await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) || + "https://api.rivet.gg"; +const namespace = + (await rl.question("Namespace (default: default): ")) || "default"; +const runnerName = await rl.question("Runner name to delete: "); + +rl.close(); + +if (!runnerName) { + console.error("Error: Runner name is required"); + process.exit(1); +} + +const response = await fetch( + `${endpoint}/runner-configs/${runnerName}?namespace=${namespace}`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${rivetToken}`, + }, + }, +); + +if (!response.ok) { + console.error(`Error: ${response.status} ${response.statusText}`); + console.error(await response.text()); + process.exit(1); +} + +console.log(`✅ Successfully deleted runner configuration "${runnerName}"!`); \ No newline at end of file diff --git a/scripts/run-config/list-run-config.ts b/scripts/run-config/list-run-config.ts new file mode 100755 index 0000000000..4f3f6a7023 --- /dev/null +++ b/scripts/run-config/list-run-config.ts @@ -0,0 +1,44 @@ +#!/usr/bin/env tsx + +import * as readline from "readline/promises"; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const rivetToken = process.env.RIVET_TOKEN; +if (!rivetToken) { + console.error("Error: RIVET_TOKEN environment variable is not set"); + process.exit(1); +} + +const endpoint = + process.env.RIVET_ENDPOINT || + (await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) || + "https://api.rivet.gg"; +const namespace = + (await rl.question("Namespace (default: default): ")) || "default"; + +rl.close(); + +const response = await fetch( + `${endpoint}/runner-configs?namespace=${namespace}`, + { + method: "GET", + headers: { + Authorization: `Bearer ${rivetToken}`, + }, + }, +); + +if (!response.ok) { + console.error(`Error: ${response.status} ${response.statusText}`); + console.error(await response.text()); + process.exit(1); +} + +const data = await response.json(); + +// Just show the raw formatted JSON +console.log(JSON.stringify(data, null, 2)); \ No newline at end of file diff --git a/scripts/run-config/package.json b/scripts/run-config/package.json new file mode 100644 index 0000000000..904a4375db --- /dev/null +++ b/scripts/run-config/package.json @@ -0,0 +1,9 @@ +{ + "name": "@rivetkit/run-config-scripts", + "private": true, + "type": "module", + "devDependencies": { + "@types/node": "^20.0.0", + "tsx": "^4.0.0" + } +} \ No newline at end of file