@sandblocks/cli 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -13387,7 +13387,7 @@ async function deployUnlocked(args, dependencies) {
13387
13387
  await deployDevelopmentUnlocked(context, loaded, preview);
13388
13388
  return;
13389
13389
  }
13390
- const deploymentTarget = await resolveDeploymentTarget(context, process.env.SANDBLOCKS_SANDBOX_TARGET_HOST ?? preview.targetHost);
13390
+ const deploymentTarget = await resolveDeploymentTarget(context, serviceMemoryReservation(preview.services), process.env.SANDBLOCKS_SANDBOX_TARGET_HOST ?? preview.targetHost);
13391
13391
  const targetHost = deploymentTarget.targetHost;
13392
13392
  context.state.deploymentHostId = deploymentTarget.hostId;
13393
13393
  context.state.deploymentWorkerId = deploymentTarget.workerId;
@@ -13428,6 +13428,7 @@ async function deployUnlocked(args, dependencies) {
13428
13428
  apiUrl: context.apiUrl,
13429
13429
  apiKey: context.apiKey,
13430
13430
  idempotencyKey: `preview:${deploymentId}:build-import`,
13431
+ memoryReservationBytes: 2 * 1024 * 1024 * 1024,
13431
13432
  source: dependencies.source,
13432
13433
  ..."image" in loaded.manifest.workspace && loaded.manifest.workspace.image ? { workspaceImage: loaded.manifest.workspace.image } : {}
13433
13434
  });
@@ -14003,15 +14004,22 @@ async function resolveDevelopmentTarget(context, fallback) {
14003
14004
  targetHost
14004
14005
  };
14005
14006
  }
14006
- async function resolveDeploymentTarget(context, fallback) {
14007
+ async function resolveDeploymentTarget(context, memoryReservationBytes, fallback) {
14007
14008
  const project = encodeURIComponent(context.state.projectId);
14008
- const workerBody = await request(context.apiUrl, context.apiKey, `/v1/projects/${project}/workers`);
14009
- const workers = Array.isArray(workerBody.workers) ? workerBody.workers : [];
14010
14009
  const requestedPool = process.env.SANDBLOCKS_DEPLOYMENT_WORKER_POOL?.trim() || process.env.SANDBLOCKS_RUNTIME_WORKER_POOL?.trim();
14011
- const eligible = workers.filter((worker2) => worker2?.status === "online" && Array.isArray(worker2.roles) && worker2.roles.includes("runtime"));
14012
- const worker = eligible.find((candidate) => typeof fallback === "string" && candidate?.configuration?.targetAddress === fallback.trim()) ?? eligible.find((candidate) => requestedPool && candidate.pool === requestedPool) ?? eligible[0];
14013
- if (!worker?.id)
14014
- throw new Error("no online deployment worker is available");
14010
+ const [workerBody, placementBody] = await Promise.all([
14011
+ request(context.apiUrl, context.apiKey, `/v1/projects/${project}/workers`),
14012
+ request(context.apiUrl, context.apiKey, `/v1/projects/${project}/placement/explain?kind=workspace.service.deploy&role=runtime&memoryReservationBytes=${memoryReservationBytes}${requestedPool ? `&pool=${encodeURIComponent(requestedPool)}` : ""}`)
14013
+ ]);
14014
+ const workers = Array.isArray(workerBody.workers) ? workerBody.workers : [];
14015
+ const candidates = Array.isArray(placementBody?.explanation?.candidates) ? placementBody.explanation.candidates : [];
14016
+ const eligibleWorkerIds = new Set(candidates.filter((candidate) => candidate?.eligible === true).map((candidate) => candidate.workerId));
14017
+ const eligible = workers.filter((worker2) => worker2?.status === "online" && Array.isArray(worker2.roles) && worker2.roles.includes("runtime") && eligibleWorkerIds.has(worker2.id));
14018
+ const worker = eligible.find((candidate) => typeof fallback === "string" && candidate?.configuration?.targetAddress === fallback.trim()) ?? eligible[0];
14019
+ if (!worker?.id) {
14020
+ const reasons = candidates.filter((candidate) => candidate?.workerId).map((candidate) => `${candidate.workerName ?? candidate.workerId}: ${(candidate.reasons ?? []).join(", ")}`).join("; ");
14021
+ throw new Error(`no eligible deployment worker is available${reasons ? ` (${reasons})` : ""}`);
14022
+ }
14015
14023
  let configuredTarget = worker?.configuration?.targetAddress;
14016
14024
  if (!configuredTarget && worker.hostId) {
14017
14025
  const legacyHosts = await request(context.apiUrl, context.apiKey, `/v1/projects/${project}/hosts`);
@@ -14141,6 +14149,7 @@ async function importSource(input) {
14141
14149
  "x-sandblocks-workspace-id": input.workspaceId,
14142
14150
  ...input.sandboxId ? { "x-sandblocks-sandbox-id": input.sandboxId } : {},
14143
14151
  "x-sandblocks-worker-pool": input.pool,
14152
+ ...input.memoryReservationBytes ? { "x-sandblocks-memory-reservation-bytes": String(input.memoryReservationBytes) } : {},
14144
14153
  ...input.workspaceImage ? { "x-sandblocks-workspace-image": input.workspaceImage } : {},
14145
14154
  "idempotency-key": input.idempotencyKey
14146
14155
  },
@@ -16649,4 +16658,4 @@ export {
16649
16658
  parse2 as parse
16650
16659
  };
16651
16660
 
16652
- //# debugId=1BF5DC414419B92F64756E2164756E21
16661
+ //# debugId=818C8E6D2946F5CD64756E2164756E21