@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 79 lines 2.77 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Effect from "effect/Effect";
3 import { DEFAULT_NETWORK } from "../../networkQuota.ts";
4
5 export const REGION = "us-central1";
6 export const ZONE = "us-central1-a";
7 export const MARKER = "alchemy-gcp-instance-smoke";
8 export const DATA_DEVICE = "smoke-data";
9 export const WEB_TAG = "alchemy-smoke-web";
10
11 /**
12 * Boots a tiny HTTP server on :80 serving `/index.html`, which carries the
13 * marker, the hostname, and whether the extra data disk is visible to the
14 * guest (`/dev/disk/by-id/google-{DATA_DEVICE}`).
15 */
16 const STARTUP_SCRIPT = `#!/bin/bash
17 set -eu
18 mkdir -p /srv/www
19 if [ -e /dev/disk/by-id/google-${DATA_DEVICE} ]; then DISK=present; else DISK=missing; fi
20 printf '%s host=%s disk=%s\\n' '${MARKER}' "$(hostname)" "$DISK" > /srv/www/index.html
21 cd /srv/www
22 nohup python3 -m http.server 80 >/var/log/smoke-http.log 2>&1 &
23 `;
24
25 /**
26 * A tcp:80 firewall on the project's `default` network, a static external address, an extra
27 * data disk, and an e2-micro Debian VM that uses all of them. `phase` drives
28 * the label/metadata update step of the smoke.
29 */
30 export const webVm = (phase: "initial" | "updated") =>
31 Effect.gen(function* () {
32 const firewall = yield* GCP.Compute.Firewall("SmokeAllowHttp", {
33 network: DEFAULT_NETWORK,
34 allowed: [{ protocol: "tcp", ports: ["80"] }],
35 sourceRanges: ["0.0.0.0/0"],
36 targetTags: [WEB_TAG],
37 });
38 const address = yield* GCP.Compute.Address("SmokeAddress", {
39 region: REGION,
40 });
41 const disk = yield* GCP.Compute.Disk("SmokeData", {
42 zone: ZONE,
43 sizeGb: 10,
44 });
45 const instance = yield* GCP.Compute.Instance("SmokeVm", {
46 zone: ZONE,
47 machineType: "e2-micro",
48 sourceImage: "projects/debian-cloud/global/images/family/debian-12",
49 network: `global/networks/${DEFAULT_NETWORK}`,
50 // The auto-mode `default` network's subnet in REGION is also `default`.
51 subnetwork: `regions/${REGION}/subnetworks/${DEFAULT_NETWORK}`,
52 natIP: address.address.as<string>(),
53 attachedDisks: [
54 {
55 source: disk.selfLink.as<string>(),
56 deviceName: DATA_DEVICE,
57 },
58 ],
59 tags: [WEB_TAG],
60 labels: phase === "initial" ? { smoke: "instance" } : { smoke: "instance", phase: "updated" },
61 metadata: {
62 "startup-script": STARTUP_SCRIPT,
63 "smoke-phase": phase,
64 },
65 });
66 return {
67 instanceName: instance.instanceName,
68 instanceId: instance.instanceId,
69 status: instance.status,
70 natIP: instance.natIP,
71 labels: instance.labels,
72 metadata: instance.metadata,
73 attachedDisks: instance.attachedDisks,
74 addressName: address.addressName,
75 address: address.address,
76 diskName: disk.diskName,
77 firewallName: firewall.firewallName,
78 };
79 });