ai-sdk-sandbox-gce 0.3.1 → 0.3.3
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/CHANGELOG.md +21 -0
- package/README.md +86 -28
- package/dist/client/lifecycle/create-session.d.ts +11 -1
- package/dist/client/lifecycle/create-session.js +23 -3
- package/dist/client/lifecycle/sandbox-template.d.ts +15 -4
- package/dist/client/lifecycle/sandbox-template.js +20 -9
- package/dist/client/transport/sandbox-service-client.d.ts +2 -0
- package/dist/client/transport/sandbox-service-client.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/proxy/idle-exit.d.ts +14 -0
- package/dist/proxy/idle-exit.js +22 -0
- package/dist/proxy/main.d.ts +2 -0
- package/dist/proxy/main.js +28 -4
- package/dist/server/compute/compute-api.d.ts +11 -2
- package/dist/server/compute/compute-api.js +13 -4
- package/dist/server/config.js +51 -0
- package/dist/server/http/routes.js +5 -0
- package/dist/server/sandboxes/sandboxes.d.ts +99 -13
- package/dist/server/sandboxes/sandboxes.js +346 -62
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# ai-sdk-sandbox-gce
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7afcb0c: The sandbox service takes `SANDBOX_PROFILE=cost|fast`, to trade how fast a sandbox starts against what the service costs at rest. `cost`, the default, is the service as it was: nothing runs but the sandboxes, and a sandbox from a template starts in some 35 to 40 s. `fast` starts one in a few seconds, for one machine of `SANDBOX_MACHINE_TYPE` per template used in the last 24 h and the egress proxy running all the time: the service keeps a machine booted from each template in use, which the next creation from that template takes as it is, booted or still booting, and makes the next one meanwhile. A machine that waited 24 h without a creation is deleted without a replacement: a template no longer used costs a day of its machine at most. See "Speed or cost" in the README.
|
|
8
|
+
|
|
9
|
+
The profile only sets the defaults of two settings, each its own variable: `SANDBOX_WARM_POOL`, how many machines are kept booted per template (`0`, `1` with `fast`), and `SANDBOX_PROXY_ALWAYS_ON`, which never stops the proxy's machine of `SANDBOX_PROXY_INSTANCE` once no sandbox runs (`false`, `true` with `fast`). With `fast` and `SANDBOX_PROXY_INSTANCE`, leave the lines of `SANDBOX_PROXY_IDLE_EXIT_MINUTES` out of the proxy's unit.
|
|
10
|
+
|
|
11
|
+
A sandbox taken from the pool keeps its machine's name, `sbx-pool-<hex>`, since Compute Engine cannot rename a running machine: its sandbox's name is on its label `ai-sdk-sandbox-name`. The service's role needs no new permission: it already has `compute.instances.setLabels`.
|
|
12
|
+
|
|
13
|
+
## 0.3.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- b40ea5d: `prepareGceSandboxService({ url, auth })` has the service boot its egress proxy ahead of a sandbox, when it starts and stops it (`SANDBOX_PROXY_INSTANCE`), without waiting for it: call it as soon as a sandbox is likely to be asked for, and the sandbox finds the proxy up rather than waiting some 40 s for its machine. The service answers it at `POST /v1/prepare`; a service of an earlier version answers 404, which the client takes as nothing to do.
|
|
18
|
+
|
|
19
|
+
Should no sandbox come, the proxy exits after `SANDBOX_PROXY_IDLE_EXIT_MINUTES` with no sandbox, with the exit code 100, on which the unit of the README stops its machine: set to 10 minutes there. The proxy never exits by itself without the variable: leave it out of the unit of a proxy always on.
|
|
20
|
+
- b40ea5d: The proxy's startup script in the README lets systemd start the proxy as its machine boots again, some 25 s before the startup script runs: a sandbox waited for the script since 0.3.0, about 60 s for a stopped proxy rather than 35 s. A condition of its unit (`ExecCondition`) only lets the proxy start at boot when it is the version the script pins, its new `VERSION` line: after a change of version, the script upgrades it and starts it, as 0.3.0 does. The script also restarts the network's resolver only when its settings change. Hand the new script to the proxy's machine (`gcloud compute instances add-metadata … --metadata-from-file=startup-script=proxy-startup.sh`).
|
|
21
|
+
- a9d2fe3: The sandbox service's image is published to Docker Hub with each release, `docker.io/fpasquet/ai-sdk-sandbox-gce:<version>`, with a provenance attestation: deploy it with `gcloud run deploy --image`, rather than writing a `Dockerfile` and having Cloud Build make it with an account of its own. The README deploys it so.
|
|
22
|
+
- b40ea5d: The client deletes a template's throwaway sandbox once the sandbox made from the template runs, rather than as soon as the template is saved. With `SANDBOX_PROXY_INSTANCE`, no sandbox ran in between: the service stopped the egress proxy, and the sandbox that followed waited a whole minute for it to boot again.
|
|
23
|
+
|
|
3
24
|
## 0.3.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -134,15 +134,27 @@ gcloud compute instances create sandbox-proxy --zone=$ZONE --machine-type=e2-sma
|
|
|
134
134
|
```bash title="proxy-startup.sh"
|
|
135
135
|
#!/bin/sh
|
|
136
136
|
set -e
|
|
137
|
+
# The version of the proxy: the one your application depends on.
|
|
138
|
+
VERSION=0.3.3
|
|
139
|
+
# Writes $2 to the file $1 when it differs, and says whether it did.
|
|
140
|
+
changed() {
|
|
141
|
+
mkdir -p "$(dirname "$1")"
|
|
142
|
+
if printf '%b' "$2" | cmp -s - "$1"; then return 1; fi
|
|
143
|
+
printf '%b' "$2" > "$1"
|
|
144
|
+
}
|
|
137
145
|
# Public resolvers, not the metadata server's, which the sandboxes' response policy answers.
|
|
138
|
-
mkdir -p /etc/systemd/resolved.conf.d
|
|
139
146
|
# After gce-resolved.conf, which adds the metadata server: the empty DNS= resets the list.
|
|
140
|
-
|
|
147
|
+
dns=false
|
|
148
|
+
if changed /etc/systemd/resolved.conf.d/public-dns.conf '[Resolve]\nDNS=\nDNS=8.8.8.8 1.1.1.1\nDomains=~.\n'; then
|
|
149
|
+
dns=true
|
|
150
|
+
fi
|
|
141
151
|
for network in /run/systemd/network/*.network; do
|
|
142
|
-
|
|
143
|
-
|
|
152
|
+
if changed "/etc/systemd/network/$(basename "$network").d/no-dhcp-dns.conf" '[DHCPv4]\nUseDNS=false\n'; then
|
|
153
|
+
dns=true
|
|
154
|
+
fi
|
|
144
155
|
done
|
|
145
|
-
|
|
156
|
+
# Restarted on a change only: from the second boot on, the proxy already runs, resolving names.
|
|
157
|
+
if [ "$dns" = true ]; then systemctl restart systemd-networkd systemd-resolved; fi
|
|
146
158
|
# Node.js and the Ops Agent from their signed apt repositories: no script piped into a shell.
|
|
147
159
|
install -m 0755 -d /etc/apt/keyrings
|
|
148
160
|
if ! command -v npm >/dev/null; then
|
|
@@ -154,8 +166,8 @@ if ! command -v npm >/dev/null; then
|
|
|
154
166
|
fi
|
|
155
167
|
# Installed again whenever the pinned version changes: the proxy then restarts on it, below.
|
|
156
168
|
restart=false
|
|
157
|
-
if ! npm ls --global ai-sdk-sandbox-gce
|
|
158
|
-
npm install --global ai-sdk-sandbox-gce
|
|
169
|
+
if ! npm ls --global "ai-sdk-sandbox-gce@$VERSION" >/dev/null 2>&1; then
|
|
170
|
+
npm install --global "ai-sdk-sandbox-gce@$VERSION"
|
|
159
171
|
restart=true
|
|
160
172
|
fi
|
|
161
173
|
# Its logs, the refusals among them, sent to Cloud Logging by the Ops Agent.
|
|
@@ -186,8 +198,17 @@ After=network-online.target
|
|
|
186
198
|
Wants=network-online.target
|
|
187
199
|
|
|
188
200
|
[Service]
|
|
201
|
+
# Started at boot only when it is the version this script pins: an earlier one would take the
|
|
202
|
+
# sandboxes the service registers meanwhile, and forget them as the script upgrades it.
|
|
203
|
+
ExecCondition=+/usr/local/bin/ai-sdk-sandbox-proxy-pinned
|
|
189
204
|
ExecStart=/bin/sh -c 'SANDBOX_PROXY_TOKEN=$(/usr/local/bin/ai-sdk-sandbox-proxy-token) exec ai-sdk-sandbox-gce proxy'
|
|
190
205
|
Restart=always
|
|
206
|
+
# With SANDBOX_PROXY_INSTANCE on the service: after 10 minutes with no sandbox, the proxy exits
|
|
207
|
+
# with 100 and its machine stops, should no sandbox come after prepareGceSandboxService(). Leave
|
|
208
|
+
# these three lines out for a proxy always on.
|
|
209
|
+
Environment=SANDBOX_PROXY_IDLE_EXIT_MINUTES=10
|
|
210
|
+
RestartPreventExitStatus=100
|
|
211
|
+
ExecStopPost=+/bin/sh -c 'if [ "$$EXIT_STATUS" = 100 ]; then systemctl poweroff; fi'
|
|
191
212
|
DynamicUser=yes
|
|
192
213
|
# Every sandbox holds up to SANDBOX_PROXY_MAX_CONNECTIONS (128) connections at once.
|
|
193
214
|
LimitNOFILE=65536
|
|
@@ -200,9 +221,20 @@ if ! cmp -s /tmp/ai-sdk-sandbox-proxy.service /etc/systemd/system/ai-sdk-sandbox
|
|
|
200
221
|
systemctl daemon-reload
|
|
201
222
|
restart=true
|
|
202
223
|
fi
|
|
203
|
-
#
|
|
204
|
-
#
|
|
205
|
-
|
|
224
|
+
# Whether the installed proxy is the version the startup script in the metadata pins: read anew at
|
|
225
|
+
# each boot, before this script runs again.
|
|
226
|
+
cat > /usr/local/bin/ai-sdk-sandbox-proxy-pinned <<'SCRIPT'
|
|
227
|
+
#!/bin/sh
|
|
228
|
+
set -e
|
|
229
|
+
pinned=$(curl -fsS -H Metadata-Flavor:Google \
|
|
230
|
+
http://metadata.google.internal/computeMetadata/v1/instance/attributes/startup-script \
|
|
231
|
+
| sed -n 's/^VERSION=//p')
|
|
232
|
+
npm ls --global "ai-sdk-sandbox-gce@$pinned" >/dev/null 2>&1
|
|
233
|
+
SCRIPT
|
|
234
|
+
chmod 755 /usr/local/bin/ai-sdk-sandbox-proxy-pinned
|
|
235
|
+
# Started by systemd as the machine boots, seconds before this script runs, when its package is
|
|
236
|
+
# the pinned one; started here otherwise, once upgraded.
|
|
237
|
+
systemctl enable --quiet ai-sdk-sandbox-proxy
|
|
206
238
|
if [ "$restart" = true ]; then
|
|
207
239
|
systemctl restart ai-sdk-sandbox-proxy
|
|
208
240
|
else
|
|
@@ -210,7 +242,7 @@ else
|
|
|
210
242
|
fi
|
|
211
243
|
```
|
|
212
244
|
|
|
213
|
-
Pin `ai-sdk-sandbox-gce` to the version your application depends on, here and in the two images below: every side checks that the others speak its protocol. Every version published by the release workflow carries a [provenance attestation](https://docs.npmjs.com/generating-provenance-statements): `npm audit signatures` checks it, in a project that depends on the package. To upgrade the proxy, change
|
|
245
|
+
Pin `ai-sdk-sandbox-gce` to the version your application depends on, here and in the two images below: every side checks that the others speak its protocol. Every version published by the release workflow carries a [provenance attestation](https://docs.npmjs.com/generating-provenance-statements): `npm audit signatures` checks it, in a project that depends on the package. To upgrade the proxy, change `VERSION` in the script, hand it to the machine again, and reboot it, or let the service start it with the next sandbox if it is stopped:
|
|
214
246
|
|
|
215
247
|
```bash
|
|
216
248
|
gcloud compute instances add-metadata sandbox-proxy --zone=$ZONE \
|
|
@@ -218,7 +250,7 @@ gcloud compute instances add-metadata sandbox-proxy --zone=$ZONE \
|
|
|
218
250
|
gcloud compute instances reset sandbox-proxy --zone=$ZONE
|
|
219
251
|
```
|
|
220
252
|
|
|
221
|
-
The proxy need not run when no sandbox does: set `SANDBOX_PROXY_INSTANCE=sandbox-proxy` on the service (step 4), which then starts it with the first sandbox, booting alongside it, and stops it once none runs. Its startup script runs again at each boot, and its registrations, held in memory, are made again by the sandboxes that start.
|
|
253
|
+
The proxy need not run when no sandbox does: set `SANDBOX_PROXY_INSTANCE=sandbox-proxy` on the service (step 4), which then starts it with the first sandbox, booting alongside it, and stops it once none runs. A sandbox then waits some 40 s for the proxy to boot: call `prepareGceSandboxService()` (see [Usage](#usage)) as soon as one is likely to be asked for, and it finds the proxy up. Its startup script runs again at each boot, and its registrations, held in memory, are made again by the sandboxes that start.
|
|
222
254
|
|
|
223
255
|
### 3. The sandbox image
|
|
224
256
|
|
|
@@ -244,7 +276,7 @@ echo "deb [signed-by=/etc/apt/keyrings/nodesource.asc] https://deb.nodesource.co
|
|
|
244
276
|
> /etc/apt/sources.list.d/nodesource.list
|
|
245
277
|
apt-get update
|
|
246
278
|
apt-get install -y nodejs
|
|
247
|
-
npm install --global ai-sdk-sandbox-gce@0.3.
|
|
279
|
+
npm install --global ai-sdk-sandbox-gce@0.3.3 pnpm@10
|
|
248
280
|
|
|
249
281
|
# The sandbox's user: sudo without a password, and Docker.
|
|
250
282
|
useradd --create-home --shell /bin/bash agent
|
|
@@ -271,13 +303,7 @@ The agent runs as root and starts the commands as `agent`. It does not wait for
|
|
|
271
303
|
|
|
272
304
|
### 4. The service
|
|
273
305
|
|
|
274
|
-
The service's image is the package
|
|
275
|
-
|
|
276
|
-
```dockerfile title="Dockerfile"
|
|
277
|
-
FROM node:24-bookworm-slim
|
|
278
|
-
RUN npm install --global --silent ai-sdk-sandbox-gce@0.3.0 && npm cache clean --force
|
|
279
|
-
CMD ["ai-sdk-sandbox-gce", "serve"]
|
|
280
|
-
```
|
|
306
|
+
The service's image is published on Docker Hub with each release, `docker.io/fpasquet/ai-sdk-sandbox-gce:<version>`: Node.js and the package, built by the release workflow from the version on npm. Deploy the version your application depends on. Each image carries a provenance attestation, which `gh attestation verify oci://docker.io/fpasquet/ai-sdk-sandbox-gce:0.3.3 --owner fpasquet` checks; its [`Dockerfile`](https://github.com/fpasquet/ai-sdk-harness/blob/main/packages/sandbox-gce/Dockerfile) builds the same image from your own registry.
|
|
281
307
|
|
|
282
308
|
Its service account gets a role of its own, with what the service calls and nothing else, limited by a condition to the names it uses: the sandboxes' machines and disks (`sbx-`), the proxy's machine, the sandbox images and templates (`ai-sdk-`).
|
|
283
309
|
|
|
@@ -315,14 +341,8 @@ for secret in sandbox-agent-secret sandbox-proxy-token sandbox-service-token; do
|
|
|
315
341
|
--member=serviceAccount:sandboxes@$PROJECT.iam.gserviceaccount.com --role=roles/secretmanager.secretAccessor
|
|
316
342
|
done
|
|
317
343
|
|
|
318
|
-
|
|
319
|
-
gcloud iam service-accounts create sandboxes-build
|
|
320
|
-
gcloud projects add-iam-policy-binding $PROJECT \
|
|
321
|
-
--member=serviceAccount:sandboxes-build@$PROJECT.iam.gserviceaccount.com --role=roles/run.builder
|
|
322
|
-
|
|
323
|
-
gcloud run deploy sandboxes --region=$REGION --source=. \
|
|
344
|
+
gcloud run deploy sandboxes --region=$REGION --image=docker.io/fpasquet/ai-sdk-sandbox-gce:0.3.3 \
|
|
324
345
|
--service-account=sandboxes@$PROJECT.iam.gserviceaccount.com \
|
|
325
|
-
--build-service-account=projects/$PROJECT/serviceAccounts/sandboxes-build@$PROJECT.iam.gserviceaccount.com \
|
|
326
346
|
--network=sandboxes --subnet=service --vpc-egress=private-ranges-only \
|
|
327
347
|
--no-allow-unauthenticated --min-instances=0 --timeout=3600 --concurrency=1000 \
|
|
328
348
|
--set-env-vars=SANDBOX_ZONE=$ZONE,SANDBOX_IMAGE=family/ai-sdk-sandbox \
|
|
@@ -337,7 +357,7 @@ gcloud run deploy sandboxes --region=$REGION --source=. \
|
|
|
337
357
|
What these settings are for:
|
|
338
358
|
|
|
339
359
|
- `--network`, `--subnet`, `--vpc-egress`: Direct VPC egress, so that the service reaches the agents and the proxy on their internal addresses.
|
|
340
|
-
- `--
|
|
360
|
+
- `--image`: Cloud Run resolves the tag to its digest when it deploys a revision, which runs that image whatever is pushed under the tag later. Nothing is built in your project: no Cloud Build, and no build account to keep away from the agents' tokens.
|
|
341
361
|
- `sandboxService`: create, stop, start and delete the machines, save a template as an image, start and stop the proxy; nothing outside the names of the condition. A missing permission shows in `pnpm test:e2e`.
|
|
342
362
|
- `SANDBOX_PROXY_INSTANCE`: the proxy only runs while a sandbox does. `SANDBOX_MAX_RUNNING`: the machines running at once, a cap on the bill. `SANDBOX_MAX_RUN_HOURS`: Compute Engine stops a machine after so long, whatever happens.
|
|
343
363
|
- `SANDBOX_SERVICE_TOKEN`: a second lock beside Cloud Run's IAM, should the service ever be deployed open; the client hands it over as `serviceToken`. The service refuses to start on Cloud Run without it, unless `SANDBOX_INSECURE_NO_TOKEN=true`.
|
|
@@ -402,6 +422,19 @@ try {
|
|
|
402
422
|
|
|
403
423
|
`auth` takes `'gcloud'` (the default: `gcloud auth print-identity-token`), `'metadata'` (the workload's service account on Google Cloud), `'none'`, or a function returning an identity token for the service's URL, such as one from `google-auth-library`.
|
|
404
424
|
|
|
425
|
+
When the service starts and stops the egress proxy (`SANDBOX_PROXY_INSTANCE`), the first sandbox after a quiet spell waits for the proxy's machine to boot. Ask the service to boot it as soon as a sandbox is likely to be asked for, a person reading what is about to run, say, and the sandbox finds it up:
|
|
426
|
+
|
|
427
|
+
```ts
|
|
428
|
+
import { prepareGceSandboxService } from 'ai-sdk-sandbox-gce';
|
|
429
|
+
|
|
430
|
+
// Not awaited: it only starts the proxy's machine, and an error changes nothing for the sandboxes.
|
|
431
|
+
void prepareGceSandboxService({ url: process.env.GCE_SANDBOX_URL!, auth: 'metadata' }).catch(
|
|
432
|
+
() => undefined,
|
|
433
|
+
);
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
The proxy stops again with the next sandbox that stops, or by itself after 10 minutes when none comes (`SANDBOX_PROXY_IDLE_EXIT_MINUTES` in its unit). A service that keeps its proxy always on, or of an earlier version, does nothing.
|
|
437
|
+
|
|
405
438
|
## Images and toolchains
|
|
406
439
|
|
|
407
440
|
Every sandbox boots from an image the service offers: `SANDBOX_IMAGE`, its default, and those `SANDBOX_IMAGES` names, one per toolchain say. A caller picks one by its name, never by its path:
|
|
@@ -439,6 +472,28 @@ const sandboxSession = await createGceNetworkSandboxSession({
|
|
|
439
472
|
await sandboxSession.destroy();
|
|
440
473
|
```
|
|
441
474
|
|
|
475
|
+
## Speed or cost
|
|
476
|
+
|
|
477
|
+
`SANDBOX_PROFILE` on the service trades how fast a sandbox starts against what the service costs at rest. It only sets defaults: each setting below can be set on its own.
|
|
478
|
+
|
|
479
|
+
| Profile | At rest | A sandbox from a template |
|
|
480
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
481
|
+
| `cost` (default) | Nothing runs: the disks of stopped sandboxes and the templates' images only. With `SANDBOX_PROXY_INSTANCE`, the proxy runs while a sandbox does | Some 35 to 40 s: a machine boots for it |
|
|
482
|
+
| `fast` | One machine of `SANDBOX_MACHINE_TYPE` and its disk for each template used in the last 24 h, all the time, at its Spot price with `SANDBOX_SPOT=true`; and the proxy's machine, always on | A few seconds when the pool's machine has booted, less than a cold start while it boots |
|
|
483
|
+
|
|
484
|
+
`fast` keeps a machine booted from each template in use, the warm pool (`SANDBOX_WARM_POOL=1`, machines per template), and never stops the proxy (`SANDBOX_PROXY_ALWAYS_ON=true`). A creation from a template takes one of its machines as it is, and the service creates the next one in the same request, without waiting for it to boot: Cloud Run throttles the service's CPU once it has answered, so nothing is left to run after. Each machine runs some 730 hours a month: see [Compute Engine's prices](https://cloud.google.com/compute/vm-instance-pricing) for your machine type and region.
|
|
485
|
+
|
|
486
|
+
- Only a creation from a template takes from the pool: `template: await agent.getSandboxTemplate()`. A creation without one, or a resume, boots its machine as before.
|
|
487
|
+
- A machine of the pool never ran an agent: it boots from the template, as a new sandbox does. Once taken it is the sandbox's, and never goes back to the pool.
|
|
488
|
+
- Each template has its pool: two harnesses, Claude Code and Codex say, keep a machine each. A new template (a new version of the package or of the sandbox image) gets its own on its first creation.
|
|
489
|
+
- A machine that waited 24 h without a creation is deleted, without a replacement, by the next creation that meets it, whatever its template: a template no longer used costs a day of its machine at most.
|
|
490
|
+
- A creation takes a running machine of its template first, or else one still booting, the one booting longest: it is ready sooner than a machine booted for the creation. Two creations in a row: the second takes the machine the first one started.
|
|
491
|
+
- A machine taken from the pool keeps its name, `sbx-pool-<hex>`: Compute Engine cannot rename a running machine. The sandbox's name is on its label `ai-sdk-sandbox-name`, by which the service finds it.
|
|
492
|
+
- `SANDBOX_MAX_RUNNING` does not count the pool's machines, and they do not keep the proxy up.
|
|
493
|
+
- `SANDBOX_MAX_RUN_HOURS` applies to the pool's machines as to every other, the bill's guard: for a sandbox taken from the pool, Compute Engine counts it from the machine's boot in the pool, 24 h ago at most. How long a session lasts is the application's to decide, not the limit's. With `SANDBOX_SPOT=true`, Compute Engine may take a machine back. A machine stopped either way is deleted by the next creation that meets it, and the pool fills again.
|
|
494
|
+
- With `SANDBOX_PROXY_INSTANCE`, the service starts the proxy with the first sandbox and leaves it running: leave the three lines of `SANDBOX_PROXY_IDLE_EXIT_MINUTES` out of its unit, or the proxy stops itself after 10 minutes with no sandbox. Without `SANDBOX_PROXY_INSTANCE`, the proxy is always on anyway.
|
|
495
|
+
- Back to `cost`, the next creation from a template takes what is left in its pool, and makes nothing more.
|
|
496
|
+
|
|
442
497
|
## Stopping and resuming
|
|
443
498
|
|
|
444
499
|
`stop()` suspends the sandbox: the processes this session started are stopped, the proxy forgets its credentials, then the machine is stopped, its disk kept. Resume it later, from this process or another one:
|
|
@@ -582,6 +637,9 @@ Docker pulls images from Docker Hub through the proxy: allow `registry-1.docker.
|
|
|
582
637
|
| `SANDBOX_MAX_RUN_HOURS` | none | The longest a machine runs at a time: Compute Engine stops it then (`maxRunDuration`), disk kept, whatever the service or the application do. 30 s at least |
|
|
583
638
|
| `SANDBOX_RECONCILE_MINUTES` | `10` | How often, at most, the service makes the proxy forget the sandboxes whose machine no longer runs, in the background of a creation or a resume. A sandbox of another service sharing the proxy in the zone is left alone, under another `SANDBOX_INSTANCE_PREFIX`. `0` for never: a proxy shared with a service of another zone or project |
|
|
584
639
|
| `SANDBOX_PROXY_INSTANCE` | none | The egress proxy's machine, in the sandboxes' zone: started with the first sandbox that runs, stopped once none does. Always on without it |
|
|
640
|
+
| `SANDBOX_PROFILE` | `cost` | `cost` or `fast`: the defaults of the two settings below, see [Speed or cost](#speed-or-cost) |
|
|
641
|
+
| `SANDBOX_WARM_POOL` | `0`, `1` with `fast` | How many machines are kept booted from each template used in the last 24 h, for the next creations from it to take at once. Each one is billed all the time |
|
|
642
|
+
| `SANDBOX_PROXY_ALWAYS_ON` | `false`, `true` with `fast` | `true`: the service starts the proxy's machine of `SANDBOX_PROXY_INSTANCE` with the first sandbox, and never stops it. No sandbox waits for it to boot, and it is billed all the time |
|
|
585
643
|
| `SANDBOX_ALLOWED_HOSTS` | none | Hosts every sandbox may reach over HTTPS, comma-separated; `*.domain` allowed. `*`, any host, is logged as a warning at startup |
|
|
586
644
|
| `SANDBOX_BASE_URLS` | `ANTHROPIC_BASE_URL=https://api.anthropic.com,OPENAI_BASE_URL=https://api.openai.com/v1` | Base URL variables routed through the proxy, as `NAME=url` pairs |
|
|
587
645
|
| `SANDBOX_SERVICE_TOKEN` | required on Cloud Run | A secret every call must carry, beside Cloud Run's IAM |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GceNetworkSandboxSessionCreateOptions, GceNetworkSandboxSessionResumeOptions } from '../gce-settings.js';
|
|
1
|
+
import type { GceConnectionSettings, GceNetworkSandboxSessionCreateOptions, GceNetworkSandboxSessionResumeOptions } from '../gce-settings.js';
|
|
2
2
|
import { GceNetworkSandboxSession } from '../session/gce-network-sandbox-session.js';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a sandbox, a [Compute Engine](https://cloud.google.com/compute) virtual machine of its
|
|
@@ -15,6 +15,16 @@ import { GceNetworkSandboxSession } from '../session/gce-network-sandbox-session
|
|
|
15
15
|
* both.
|
|
16
16
|
*/
|
|
17
17
|
export declare function createGceNetworkSandboxSession(options: GceNetworkSandboxSessionCreateOptions): Promise<GceNetworkSandboxSession>;
|
|
18
|
+
/**
|
|
19
|
+
* Has the sandbox service at `url` boot what a sandbox needs, its egress proxy when the service
|
|
20
|
+
* starts and stops it, without waiting for it: call it as soon as a sandbox is likely to be asked
|
|
21
|
+
* for, the person who launches it still reading what will run, and the creation that follows finds
|
|
22
|
+
* the proxy up. The proxy stops again with the next sandbox that stops, or by itself when none is
|
|
23
|
+
* made. A service that does not drive its proxy, or of an earlier version, does nothing.
|
|
24
|
+
*/
|
|
25
|
+
export declare function prepareGceSandboxService(options: GceConnectionSettings & {
|
|
26
|
+
abortSignal?: AbortSignal;
|
|
27
|
+
}): Promise<void>;
|
|
18
28
|
/**
|
|
19
29
|
* Reattaches to a sandbox made by {@link createGceNetworkSandboxSession}, from this process or
|
|
20
30
|
* another one: a running sandbox as it is, a stopped one started again on its disk. Never creates
|
|
@@ -22,6 +22,16 @@ function clientOf({ url, auth = 'gcloud', serviceToken, }) {
|
|
|
22
22
|
function sessionOf(client, { name, workingDirectory }, settings) {
|
|
23
23
|
return new GceNetworkSandboxSession({ client, name, workingDirectory, processes: new Set() }, settings.ports ?? []);
|
|
24
24
|
}
|
|
25
|
+
/** Creates the sandbox `name`, from `template` when given, its builder removed once it runs. */
|
|
26
|
+
async function createFrom(client, name, { template, ...options }) {
|
|
27
|
+
try {
|
|
28
|
+
return await client.create(name, { ...options, template: template?.id });
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
// Not before: with no sandbox running in between, the service would stop the egress proxy.
|
|
32
|
+
await template?.releaseBuilder();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
/**
|
|
26
36
|
* Creates a sandbox, a [Compute Engine](https://cloud.google.com/compute) virtual machine of its
|
|
27
37
|
* own, through the sandbox service at `url`, and returns a network sandbox session on it, to hand
|
|
@@ -45,13 +55,13 @@ export async function createGceNetworkSandboxSession(options) {
|
|
|
45
55
|
assertSandboxName(name);
|
|
46
56
|
const client = clientOf(options);
|
|
47
57
|
const network = { allowedHosts, baseUrls };
|
|
48
|
-
const
|
|
58
|
+
const ready = template
|
|
49
59
|
? await ensureTemplate(client, { template, setup, network, image, requiredCommands }, abortSignal)
|
|
50
60
|
: undefined;
|
|
51
|
-
const description = await client
|
|
61
|
+
const description = await createFrom(client, name, {
|
|
52
62
|
...network,
|
|
53
63
|
image,
|
|
54
|
-
template:
|
|
64
|
+
template: ready,
|
|
55
65
|
abortSignal,
|
|
56
66
|
});
|
|
57
67
|
const session = sessionOf(client, description, options);
|
|
@@ -69,6 +79,16 @@ export async function createGceNetworkSandboxSession(options) {
|
|
|
69
79
|
throw error;
|
|
70
80
|
}
|
|
71
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Has the sandbox service at `url` boot what a sandbox needs, its egress proxy when the service
|
|
84
|
+
* starts and stops it, without waiting for it: call it as soon as a sandbox is likely to be asked
|
|
85
|
+
* for, the person who launches it still reading what will run, and the creation that follows finds
|
|
86
|
+
* the proxy up. The proxy stops again with the next sandbox that stops, or by itself when none is
|
|
87
|
+
* made. A service that does not drive its proxy, or of an earlier version, does nothing.
|
|
88
|
+
*/
|
|
89
|
+
export async function prepareGceSandboxService(options) {
|
|
90
|
+
await clientOf(options).prepare(options.abortSignal);
|
|
91
|
+
}
|
|
72
92
|
/**
|
|
73
93
|
* Reattaches to a sandbox made by {@link createGceNetworkSandboxSession}, from this process or
|
|
74
94
|
* another one: a running sandbox as it is, a stopped one started again on its disk. Never creates
|
|
@@ -17,6 +17,16 @@ interface BuildSettings {
|
|
|
17
17
|
/** Commands the image must have, checked before the setup. */
|
|
18
18
|
requiredCommands: readonly string[];
|
|
19
19
|
}
|
|
20
|
+
/** A template ready to boot from, and the builder it was made with, if this process made it. */
|
|
21
|
+
export interface ReadyTemplate {
|
|
22
|
+
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* Removes the builder, once for all the sandboxes waiting for the template: after the first of
|
|
25
|
+
* them is created, so that a sandbox always runs meanwhile and the service keeps its egress proxy
|
|
26
|
+
* up. Never fails.
|
|
27
|
+
*/
|
|
28
|
+
releaseBuilder(): Promise<void>;
|
|
29
|
+
}
|
|
20
30
|
/**
|
|
21
31
|
* The template's id: `ai-sdk-harness-template-<digest>`, the digest covering the harness's recipe
|
|
22
32
|
* and the setup commands, so that a new harness version gets a template of its own.
|
|
@@ -25,9 +35,10 @@ export declare function templateId({ template, setup }: TemplateSource): string;
|
|
|
25
35
|
/** Runs each of `setup` in the sandbox, in order, stopping at the first failure. */
|
|
26
36
|
export declare function runSetup(session: GceNetworkSandboxSession, setup: readonly string[], abortSignal?: AbortSignal): Promise<void>;
|
|
27
37
|
/**
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
30
|
-
*
|
|
38
|
+
* The template prepared by `source.template`, built the first time and reused afterwards: one
|
|
39
|
+
* sandbox is created, set up, prepared and its disk saved as an image by the service, then deleted
|
|
40
|
+
* by {@link ReadyTemplate.releaseBuilder}. Every later sandbox boots from that image, the harness
|
|
41
|
+
* already installed.
|
|
31
42
|
*/
|
|
32
|
-
export declare function ensureTemplate(client: SandboxServiceClient, source: BuildSettings & TemplateSource, abortSignal?: AbortSignal): Promise<
|
|
43
|
+
export declare function ensureTemplate(client: SandboxServiceClient, source: BuildSettings & TemplateSource, abortSignal?: AbortSignal): Promise<ReadyTemplate>;
|
|
33
44
|
export {};
|
|
@@ -26,18 +26,28 @@ export async function runSetup(session, setup, abortSignal) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* The
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* The template prepared by `source.template`, built the first time and reused afterwards: one
|
|
30
|
+
* sandbox is created, set up, prepared and its disk saved as an image by the service, then deleted
|
|
31
|
+
* by {@link ReadyTemplate.releaseBuilder}. Every later sandbox boots from that image, the harness
|
|
32
|
+
* already installed.
|
|
32
33
|
*/
|
|
33
34
|
export function ensureTemplate(client, source, abortSignal) {
|
|
34
35
|
const id = templateId(source);
|
|
35
36
|
const key = `${client.baseUrl} ${source.image ?? ''} ${id}`;
|
|
36
37
|
let ready = building.get(key);
|
|
37
38
|
if (ready === undefined) {
|
|
38
|
-
ready = client
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
ready = client.templateExists(id, source.image, abortSignal).then(async (exists) => {
|
|
40
|
+
let builder = exists ? undefined : await build(client, { ...source, id }, abortSignal);
|
|
41
|
+
return {
|
|
42
|
+
id,
|
|
43
|
+
releaseBuilder: async () => {
|
|
44
|
+
const name = builder;
|
|
45
|
+
builder = undefined;
|
|
46
|
+
if (name !== undefined)
|
|
47
|
+
await client.remove(name).catch(() => undefined);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
});
|
|
41
51
|
building.set(key, ready);
|
|
42
52
|
// A failed build is not remembered: the next sandbox tries again.
|
|
43
53
|
ready.catch(() => building.delete(key));
|
|
@@ -47,16 +57,17 @@ export function ensureTemplate(client, source, abortSignal) {
|
|
|
47
57
|
async function build(client, { template, setup, network, image, requiredCommands, id, }, abortSignal) {
|
|
48
58
|
const builder = `${TEMPLATE_PREFIX}-${id.slice(-8)}-${randomBytes(3).toString('hex')}`;
|
|
49
59
|
const { workingDirectory } = await client.create(builder, { ...network, image, abortSignal });
|
|
60
|
+
// Answered once saved, for the caller to remove it; removed here when anything fails.
|
|
50
61
|
try {
|
|
51
62
|
const session = new GceNetworkSandboxSession({ client, name: builder, workingDirectory, processes: new Set() }, []);
|
|
52
63
|
await runSetup(session, setup, abortSignal);
|
|
53
64
|
await assertRequiredCommands(session, requiredCommands, abortSignal);
|
|
54
65
|
await template.prepare({ session: session.restricted(), abortSignal });
|
|
55
|
-
// Removed below only once saved: its disk is what the template's image is made of.
|
|
56
66
|
await client.saveTemplate(builder, id, { image, abortSignal });
|
|
57
|
-
return
|
|
67
|
+
return builder;
|
|
58
68
|
}
|
|
59
|
-
|
|
69
|
+
catch (error) {
|
|
60
70
|
await client.remove(builder).catch(() => undefined);
|
|
71
|
+
throw error;
|
|
61
72
|
}
|
|
62
73
|
}
|
|
@@ -75,6 +75,8 @@ export declare class SandboxServiceClient {
|
|
|
75
75
|
}): Promise<void>;
|
|
76
76
|
/** Whether the template `id` exists, made on the image `image` (the service's default without). */
|
|
77
77
|
templateExists(id: string, image?: string, abortSignal?: AbortSignal): Promise<boolean>;
|
|
78
|
+
/** Boots what a sandbox needs ahead of it. A service without the route answers 404: it is fine. */
|
|
79
|
+
prepare(abortSignal?: AbortSignal): Promise<void>;
|
|
78
80
|
deleteTemplate(id: string, image?: string): Promise<void>;
|
|
79
81
|
/**
|
|
80
82
|
* Where a port of the sandbox is reached: a WebSocket through the service. The token is read
|
|
@@ -166,6 +166,10 @@ export class SandboxServiceClient {
|
|
|
166
166
|
});
|
|
167
167
|
return response.status !== 404;
|
|
168
168
|
}
|
|
169
|
+
/** Boots what a sandbox needs ahead of it. A service without the route answers 404: it is fine. */
|
|
170
|
+
async prepare(abortSignal) {
|
|
171
|
+
await this.call('POST', 'v1/prepare', { abortSignal, accept: [404] });
|
|
172
|
+
}
|
|
169
173
|
async deleteTemplate(id, image) {
|
|
170
174
|
await this.call('DELETE', templatePath(id, image));
|
|
171
175
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { GceSandboxImageError } from './client/errors/gce-sandbox-image-error.js
|
|
|
2
2
|
export { GceSandboxNotFoundError } from './client/errors/gce-sandbox-not-found-error.js';
|
|
3
3
|
export { GceSandboxServiceError } from './client/errors/gce-sandbox-service-error.js';
|
|
4
4
|
export type { GceAuth, GceConnectionSettings, GceCreationSettings, GceNetworkSandboxSessionCreateOptions, GceNetworkSandboxSessionResumeOptions, } from './client/gce-settings.js';
|
|
5
|
-
export { createGceNetworkSandboxSession, resumeGceNetworkSandboxSession, } from './client/lifecycle/create-session.js';
|
|
5
|
+
export { createGceNetworkSandboxSession, prepareGceSandboxService, resumeGceNetworkSandboxSession, } from './client/lifecycle/create-session.js';
|
|
6
6
|
export { GCE_SANDBOX_PROVIDER_ID } from './client/provider-id.js';
|
|
7
7
|
export { GceNetworkSandboxSession } from './client/session/gce-network-sandbox-session.js';
|
|
8
8
|
export { GceSandboxSession } from './client/session/gce-sandbox-session.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { GceSandboxImageError } from './client/errors/gce-sandbox-image-error.js';
|
|
2
2
|
export { GceSandboxNotFoundError } from './client/errors/gce-sandbox-not-found-error.js';
|
|
3
3
|
export { GceSandboxServiceError } from './client/errors/gce-sandbox-service-error.js';
|
|
4
|
-
export { createGceNetworkSandboxSession, resumeGceNetworkSandboxSession, } from './client/lifecycle/create-session.js';
|
|
4
|
+
export { createGceNetworkSandboxSession, prepareGceSandboxService, resumeGceNetworkSandboxSession, } from './client/lifecycle/create-session.js';
|
|
5
5
|
export { GCE_SANDBOX_PROVIDER_ID } from './client/provider-id.js';
|
|
6
6
|
export { GceNetworkSandboxSession } from './client/session/gce-network-sandbox-session.js';
|
|
7
7
|
export { GceSandboxSession } from './client/session/gce-sandbox-session.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The proxy's exit code once idle: its systemd unit powers the machine off on it, and only on it. */
|
|
2
|
+
export declare const IDLE_EXIT_CODE = 100;
|
|
3
|
+
/**
|
|
4
|
+
* Calls `onIdle` once no sandbox was registered for `idleMs`, counted from now: a proxy the service
|
|
5
|
+
* started ahead of a sandbox that never came, or one the service could not stop, powers its machine
|
|
6
|
+
* off rather than run unused. Returns what stops the watch.
|
|
7
|
+
*/
|
|
8
|
+
export declare function watchIdle({ idleMs, sandboxes, onIdle, now, }: {
|
|
9
|
+
idleMs: number;
|
|
10
|
+
/** How many sandboxes the proxy serves. */
|
|
11
|
+
sandboxes: () => number;
|
|
12
|
+
onIdle: () => void;
|
|
13
|
+
now?: () => number;
|
|
14
|
+
}): () => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The proxy's exit code once idle: its systemd unit powers the machine off on it, and only on it. */
|
|
2
|
+
export const IDLE_EXIT_CODE = 100;
|
|
3
|
+
/** How often the proxy checks whether it serves a sandbox. */
|
|
4
|
+
const CHECK_EVERY_MS = 30_000;
|
|
5
|
+
/**
|
|
6
|
+
* Calls `onIdle` once no sandbox was registered for `idleMs`, counted from now: a proxy the service
|
|
7
|
+
* started ahead of a sandbox that never came, or one the service could not stop, powers its machine
|
|
8
|
+
* off rather than run unused. Returns what stops the watch.
|
|
9
|
+
*/
|
|
10
|
+
export function watchIdle({ idleMs, sandboxes, onIdle, now = Date.now, }) {
|
|
11
|
+
let busyAt = now();
|
|
12
|
+
const timer = setInterval(() => {
|
|
13
|
+
if (sandboxes() > 0)
|
|
14
|
+
busyAt = now();
|
|
15
|
+
else if (now() - busyAt >= idleMs) {
|
|
16
|
+
clearInterval(timer);
|
|
17
|
+
onIdle();
|
|
18
|
+
}
|
|
19
|
+
}, Math.min(CHECK_EVERY_MS, idleMs));
|
|
20
|
+
timer.unref();
|
|
21
|
+
return () => clearInterval(timer);
|
|
22
|
+
}
|
package/dist/proxy/main.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare function proxyConfig(env: Environment): {
|
|
|
4
4
|
adminPort: number;
|
|
5
5
|
allowPrivateNetwork: boolean;
|
|
6
6
|
host: string;
|
|
7
|
+
/** How long the proxy runs with no sandbox before it exits for its machine to power off. */
|
|
8
|
+
idleExitMs?: number;
|
|
7
9
|
maxConnections: number;
|
|
8
10
|
port: number;
|
|
9
11
|
token: string;
|
package/dist/proxy/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createLogger } from '../common/logger.js';
|
|
|
2
2
|
import { DEFAULT_PROXY_ADMIN_PORT, DEFAULT_PROXY_PORT } from '../protocol/proxy.js';
|
|
3
3
|
import { createAdminServer } from './admin-server.js';
|
|
4
4
|
import { DEFAULT_MAX_CONNECTIONS, EgressProxy } from './egress-proxy.js';
|
|
5
|
+
import { IDLE_EXIT_CODE, watchIdle } from './idle-exit.js';
|
|
5
6
|
import { SandboxRegistry } from './registry.js';
|
|
6
7
|
/** The proxy's settings, from its environment, which the systemd unit of its machine sets. */
|
|
7
8
|
export function proxyConfig(env) {
|
|
@@ -15,9 +16,20 @@ export function proxyConfig(env) {
|
|
|
15
16
|
host: env['HOST'] ?? '0.0.0.0',
|
|
16
17
|
allowPrivateNetwork: env['SANDBOX_ALLOW_PRIVATE_NETWORK'] === 'true',
|
|
17
18
|
maxConnections: maxConnections(env['SANDBOX_PROXY_MAX_CONNECTIONS']),
|
|
19
|
+
idleExitMs: idleExitMs(env['SANDBOX_PROXY_IDLE_EXIT_MINUTES']),
|
|
18
20
|
token,
|
|
19
21
|
};
|
|
20
22
|
}
|
|
23
|
+
/** `SANDBOX_PROXY_IDLE_EXIT_MINUTES`, a positive integer: never exits when unset. */
|
|
24
|
+
function idleExitMs(value) {
|
|
25
|
+
if (value === undefined || value === '')
|
|
26
|
+
return undefined;
|
|
27
|
+
const parsed = Number(value);
|
|
28
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
29
|
+
throw new Error(`SANDBOX_PROXY_IDLE_EXIT_MINUTES: \`${value}\` is not a positive integer.`);
|
|
30
|
+
}
|
|
31
|
+
return parsed * 60_000;
|
|
32
|
+
}
|
|
21
33
|
/** `SANDBOX_PROXY_MAX_CONNECTIONS`, a positive integer: {@link DEFAULT_MAX_CONNECTIONS} when unset. */
|
|
22
34
|
function maxConnections(value) {
|
|
23
35
|
if (value === undefined || value === '')
|
|
@@ -42,11 +54,23 @@ export function main(env) {
|
|
|
42
54
|
const admin = createAdminServer({ registry, token: config.token, logger });
|
|
43
55
|
proxy.server.listen(config.port, config.host, () => logger.info(`Egress proxy listening on ${config.host}:${config.port}`));
|
|
44
56
|
admin.listen(config.adminPort, config.host, () => logger.info(`Administration API listening on ${config.host}:${config.adminPort}`));
|
|
57
|
+
const shutDown = (code) => {
|
|
58
|
+
proxy.close();
|
|
59
|
+
admin.closeAllConnections();
|
|
60
|
+
admin.close(() => process.exit(code));
|
|
61
|
+
};
|
|
45
62
|
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
46
|
-
process.once(signal, () =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
process.once(signal, () => shutDown(0));
|
|
64
|
+
}
|
|
65
|
+
const { idleExitMs } = config;
|
|
66
|
+
if (idleExitMs !== undefined) {
|
|
67
|
+
watchIdle({
|
|
68
|
+
idleMs: idleExitMs,
|
|
69
|
+
sandboxes: () => registry.list().length,
|
|
70
|
+
onIdle: () => {
|
|
71
|
+
logger.info(`No sandbox for ${idleExitMs / 60_000} min: exiting for the machine to stop`);
|
|
72
|
+
shutDown(IDLE_EXIT_CODE);
|
|
73
|
+
},
|
|
50
74
|
});
|
|
51
75
|
}
|
|
52
76
|
}
|
|
@@ -5,10 +5,14 @@ export interface Instance {
|
|
|
5
5
|
/** `PROVISIONING`, `STAGING`, `RUNNING`, `STOPPING`, `TERMINATED`, `SUSPENDING`, `SUSPENDED`… */
|
|
6
6
|
status: string;
|
|
7
7
|
labels?: Record<string, string>;
|
|
8
|
+
/** What the labels are changed with: Compute Engine refuses a change made on older ones. */
|
|
9
|
+
labelFingerprint?: string;
|
|
8
10
|
networkInterfaces?: {
|
|
9
11
|
networkIP?: string;
|
|
10
12
|
}[];
|
|
11
13
|
metadata?: InstanceMetadata;
|
|
14
|
+
/** When the instance was made: an RFC 3339 timestamp. */
|
|
15
|
+
creationTimestamp?: string;
|
|
12
16
|
}
|
|
13
17
|
/** The metadata of an instance: its `fingerprint` must be given back to change it. */
|
|
14
18
|
export interface InstanceMetadata {
|
|
@@ -52,8 +56,8 @@ export declare class ComputeApi {
|
|
|
52
56
|
getInstance(name: string): Promise<Instance | undefined>;
|
|
53
57
|
/** The instances of the zone whose label `key` is `value`, every page of them. */
|
|
54
58
|
listInstances(key: string, value: string): Promise<Instance[]>;
|
|
55
|
-
insertInstance(body: Record<string, unknown
|
|
56
|
-
startInstance(name: string): Promise<void>;
|
|
59
|
+
insertInstance(body: Record<string, unknown>, { wait }?: ChangeOptions): Promise<void>;
|
|
60
|
+
startInstance(name: string, { wait }?: ChangeOptions): Promise<void>;
|
|
57
61
|
resumeInstance(name: string): Promise<void>;
|
|
58
62
|
stopInstance(name: string, { wait }?: ChangeOptions): Promise<void>;
|
|
59
63
|
/** Changes how the stopped instance `name` is provisioned: from Spot to standard, say. */
|
|
@@ -63,6 +67,11 @@ export declare class ComputeApi {
|
|
|
63
67
|
* read with `fingerprint`.
|
|
64
68
|
*/
|
|
65
69
|
setMetadata(name: string, metadata: InstanceMetadata): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Replaces the labels of the instance `name`. Refused with a 412 when they changed since they were
|
|
72
|
+
* read with `fingerprint`: of two changes made on the same labels, one only goes through.
|
|
73
|
+
*/
|
|
74
|
+
setLabels(name: string, labels: Record<string, string>, fingerprint: string | undefined): Promise<void>;
|
|
66
75
|
/** Deletes the instance `name` and its disks set to go with it. Nothing when there is none. */
|
|
67
76
|
deleteInstance(name: string, { wait }?: ChangeOptions): Promise<void>;
|
|
68
77
|
/**
|