Skip to content

Commit f557664

Browse files
committed
chore(core): add scripts for run config
1 parent e456f8c commit f557664

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env tsx
2+
3+
import * as readline from "readline/promises";
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
const rivetToken = process.env.RIVET_TOKEN;
11+
if (!rivetToken) {
12+
console.error("Error: RIVET_TOKEN environment variable is not set");
13+
process.exit(1);
14+
}
15+
16+
const endpoint =
17+
process.env.RIVET_ENDPOINT ||
18+
(await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) ||
19+
"https://api.rivet.gg";
20+
const namespace =
21+
(await rl.question("Namespace (default: default): ")) || "default";
22+
const runnerName =
23+
(await rl.question("Runner name (default: serverless): ")) || "serverless";
24+
const serverlessUrl =
25+
(await rl.question(
26+
"Serverless URL (default: http://localhost:8080/api/start): ",
27+
)) || "http://localhost:8080/api/start";
28+
29+
rl.close();
30+
31+
const response = await fetch(
32+
`${endpoint}/runner-configs/${runnerName}?namespace=${namespace}`,
33+
{
34+
method: "PUT",
35+
headers: {
36+
Authorization: `Bearer ${rivetToken}`,
37+
"Content-Type": "application/json",
38+
},
39+
body: JSON.stringify({
40+
serverless: {
41+
url: serverlessUrl,
42+
headers: {},
43+
runners_margin: 1,
44+
min_runners: 1,
45+
max_runners: 3,
46+
slots_per_runner: 100,
47+
request_lifespan: 15 * 60,
48+
},
49+
}),
50+
},
51+
);
52+
53+
if (!response.ok) {
54+
console.error(`Error: ${response.status} ${response.statusText}`);
55+
console.error(await response.text());
56+
process.exit(1);
57+
}
58+
59+
console.log("✅ Successfully configured serverless runner!");
60+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env tsx
2+
3+
import * as readline from "readline/promises";
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
const rivetToken = process.env.RIVET_TOKEN;
11+
if (!rivetToken) {
12+
console.error("Error: RIVET_TOKEN environment variable is not set");
13+
process.exit(1);
14+
}
15+
16+
const endpoint =
17+
process.env.RIVET_ENDPOINT ||
18+
(await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) ||
19+
"https://api.rivet.gg";
20+
const namespace =
21+
(await rl.question("Namespace (default: default): ")) || "default";
22+
const runnerName = await rl.question("Runner name to delete: ");
23+
24+
rl.close();
25+
26+
if (!runnerName) {
27+
console.error("Error: Runner name is required");
28+
process.exit(1);
29+
}
30+
31+
const response = await fetch(
32+
`${endpoint}/runner-configs/${runnerName}?namespace=${namespace}`,
33+
{
34+
method: "DELETE",
35+
headers: {
36+
Authorization: `Bearer ${rivetToken}`,
37+
},
38+
},
39+
);
40+
41+
if (!response.ok) {
42+
console.error(`Error: ${response.status} ${response.statusText}`);
43+
console.error(await response.text());
44+
process.exit(1);
45+
}
46+
47+
console.log(`✅ Successfully deleted runner configuration "${runnerName}"!`);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env tsx
2+
3+
import * as readline from "readline/promises";
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
const rivetToken = process.env.RIVET_TOKEN;
11+
if (!rivetToken) {
12+
console.error("Error: RIVET_TOKEN environment variable is not set");
13+
process.exit(1);
14+
}
15+
16+
const endpoint =
17+
process.env.RIVET_ENDPOINT ||
18+
(await rl.question("Rivet Endpoint (default: https://api.rivet.gg): ")) ||
19+
"https://api.rivet.gg";
20+
const namespace =
21+
(await rl.question("Namespace (default: default): ")) || "default";
22+
23+
rl.close();
24+
25+
const response = await fetch(
26+
`${endpoint}/runner-configs?namespace=${namespace}`,
27+
{
28+
method: "GET",
29+
headers: {
30+
Authorization: `Bearer ${rivetToken}`,
31+
},
32+
},
33+
);
34+
35+
if (!response.ok) {
36+
console.error(`Error: ${response.status} ${response.statusText}`);
37+
console.error(await response.text());
38+
process.exit(1);
39+
}
40+
41+
const data = await response.json();
42+
43+
// Just show the raw formatted JSON
44+
console.log(JSON.stringify(data, null, 2));

scripts/run-config/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@rivetkit/run-config-scripts",
3+
"private": true,
4+
"type": "module",
5+
"devDependencies": {
6+
"@types/node": "^20.0.0",
7+
"tsx": "^4.0.0"
8+
}
9+
}

0 commit comments

Comments
 (0)