Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Teach the dev-instance CLI the porter sandbox backend

Josh Franceaff3ceb5fed9
diff --git a/scripts/dev/cli.ts b/scripts/dev/cli.ts
index 61e051060..370a6da7c 100644
--- a/scripts/dev/cli.ts
+++ b/scripts/dev/cli.ts
@@ -245,7 +245,7 @@ async function bootOnSlot(slot: string, worktree: string, branch: string): Promi
branch,
callerEnv,
watch: !opts["no-watch"] && callerEnv.DEV_INSTANCE_WATCH !== "0",
- sandbox: opts.sandbox as "local" | "sprites" | "smolmachines" | "auto",
+ sandbox: opts.sandbox as "local" | "sprites" | "smolmachines" | "porter" | "auto",
canaryChannel,
strict: opts.strict,
slack: withSlack,
@@ -644,7 +644,7 @@ async function main(): Promise<number> {
return await runDoctor({ json: opts.json, fix: opts.fix, store, slack: withSlack });
default:
console.error(
- "usage: dev [up|down|status|restart|canary|logs|doctor] [--json] [--force] [--rotate] [--strict] [--sandbox local|sprites|smolmachines|auto] [--no-slack] [--no-watch] [--org id] [--fix]",
+ "usage: dev [up|down|status|restart|canary|logs|doctor] [--json] [--force] [--rotate] [--strict] [--sandbox local|sprites|smolmachines|porter|auto] [--no-slack] [--no-watch] [--org id] [--fix]",
);
return EXIT.usage;
}
diff --git a/scripts/dev/lib/sandbox.ts b/scripts/dev/lib/sandbox.ts
index fc22780b4..6ed2abed5 100644
--- a/scripts/dev/lib/sandbox.ts
+++ b/scripts/dev/lib/sandbox.ts
@@ -7,7 +7,7 @@ import { ensureDockerDaemon } from "./postgres.ts";
import { bestEffortValue, sleep } from "./util.ts";
export interface SandboxResolution {
- backend: "local" | "sprites" | "smolmachines";
+ backend: "local" | "sprites" | "smolmachines" | "porter";
env: Record<string, string>;
detail: string;
publicApiUrl: string | null;
@@ -24,7 +24,7 @@ async function localImagePresent(image: string): Promise<boolean> {
export async function resolveSandbox(opts: {
worktree: string;
- requested: "local" | "sprites" | "smolmachines" | "auto";
+ requested: "local" | "sprites" | "smolmachines" | "porter" | "auto";
corePort: number;
lock: string;
baseEnv: Record<string, string>;
@@ -99,6 +99,47 @@ export async function resolveSandbox(opts: {
};
}
+ if (backend === "porter") {
+ const porterToken = opts.baseEnv.PORTER_DEPLOY_API_TOKEN;
+ const projectId = opts.baseEnv.PORTER_DEPLOY_PROJECT_ID;
+ const clusterId = opts.baseEnv.PORTER_DEPLOY_CLUSTER_ID;
+ if (!porterToken || !projectId || !clusterId)
+ throw new Error(
+ "--sandbox porter requires PORTER_DEPLOY_API_TOKEN, PORTER_DEPLOY_PROJECT_ID, and PORTER_DEPLOY_CLUSTER_ID in the environment (create an API token in the Porter dashboard)",
+ );
+ let porterApiUrl = opts.baseEnv.PUBLIC_API_URL || null;
+ if (!porterApiUrl) {
+ porterApiUrl = await startQuickTunnel(opts.corePort, opts.lock, opts.log);
+ if (!porterApiUrl)
+ warnings.push(
+ "cloudflared tunnel didn't come up -- agent self-API (crons/sends) won't be reachable from the sandbox",
+ );
+ }
+ const env: Record<string, string> = {
+ SANDBOX_BACKEND: "porter",
+ PORTER_DEPLOY_API_TOKEN: porterToken,
+ PORTER_DEPLOY_PROJECT_ID: projectId,
+ PORTER_DEPLOY_CLUSTER_ID: clusterId,
+ PORTER_SANDBOX_NAME_PREFIX: opts.baseEnv.PORTER_SANDBOX_NAME_PREFIX || "qmdev",
+ };
+ if (opts.baseEnv.PORTER_DEPLOY_URL) env.PORTER_DEPLOY_URL = opts.baseEnv.PORTER_DEPLOY_URL;
+ if (opts.baseEnv.PORTER_SANDBOX_IMAGE) env.PORTER_SANDBOX_IMAGE = opts.baseEnv.PORTER_SANDBOX_IMAGE;
+ if (opts.baseEnv.PORTER_SANDBOX_EGRESS_PROXY_URL)
+ env.PORTER_SANDBOX_EGRESS_PROXY_URL = opts.baseEnv.PORTER_SANDBOX_EGRESS_PROXY_URL;
+ else
+ warnings.push(
+ "PORTER_SANDBOX_EGRESS_PROXY_URL unset -- porter sandbox runs with NO egress enforcement; set it to QA the forced-proxy path",
+ );
+ if (porterApiUrl) env.PUBLIC_API_URL = porterApiUrl;
+ return {
+ backend: "porter",
+ env,
+ detail: `Porter (project ${projectId}, cluster ${clusterId})`,
+ publicApiUrl: porterApiUrl,
+ warnings,
+ };
+ }
+
const token = opts.baseEnv.SPRITES_TOKEN;
if (!token)
throw new Error("--sandbox sprites requires SPRITES_TOKEN in the environment (mint one with `sprite login`)");
diff --git a/scripts/dev/lib/types.ts b/scripts/dev/lib/types.ts
index 13ee9a549..a64f9e2cf 100644
--- a/scripts/dev/lib/types.ts
+++ b/scripts/dev/lib/types.ts
@@ -108,7 +108,7 @@ export interface BootSpec {
branch: string;
callerEnv: Record<string, string>;
watch: boolean;
- sandbox: "local" | "sprites" | "smolmachines" | "auto";
+ sandbox: "local" | "sprites" | "smolmachines" | "porter" | "auto";
canaryChannel?: string;
strict: boolean;
slack?: boolean;