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

main
ts 66 lines 2.46 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Kubernetes from "@alchemy.run/kubernetes";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import { SmokeBucket, SmokeCluster, SmokeNamespace, smokeResources } from "./smoke-resources.ts";
7
8 /**
9 * Effect-native `Kubernetes.Deployment` behind a GKE LoadBalancer. The
10 * `GCP.Storage.ReadWriteBucket` binding grants `roles/storage.objectUser`
11 * on the bucket to the Deployment's KSA Workload Identity principal; the
12 * pod authenticates through the GKE metadata server.
13 *
14 * - `GET /health` — readiness.
15 * - `PUT /objects/<key>` — write the request body, read it back.
16 * - `GET /objects/<key>` — read an object (404 when missing).
17 */
18 export class GkeSmokeApi extends Kubernetes.Deployment<GkeSmokeApi>()("GkeSmokeApi") {}
19
20 export default GkeSmokeApi.make(
21 Effect.gen(function* () {
22 const cluster = yield* SmokeCluster;
23 const ns = yield* SmokeNamespace;
24 return {
25 cluster,
26 main: import.meta.url,
27 namespace: ns.name,
28 port: 3000,
29 replicas: 1,
30 serviceType: "LoadBalancer" as const,
31 resources: smokeResources,
32 };
33 }),
34 Effect.gen(function* () {
35 const bucket = yield* GCP.Storage.ReadWriteBucket(SmokeBucket);
36
37 return {
38 fetch: Effect.gen(function* () {
39 const request = yield* HttpServerRequest;
40 const url = new URL(request.url, "http://localhost");
41 const key = url.pathname.startsWith("/objects/")
42 ? decodeURIComponent(url.pathname.slice("/objects/".length))
43 : undefined;
44
45 if (key !== undefined && request.method === "PUT") {
46 const body = yield* request.text;
47 yield* bucket.put(key, body, { contentType: "text/plain" });
48 const read = yield* bucket.get(key);
49 return yield* HttpServerResponse.json({
50 key,
51 read: read && new TextDecoder().decode(read.body),
52 });
53 }
54
55 if (key !== undefined && request.method === "GET") {
56 const read = yield* bucket.get(key);
57 return read === undefined
58 ? HttpServerResponse.text("not found", { status: 404 })
59 : HttpServerResponse.text(new TextDecoder().decode(read.body));
60 }
61
62 return yield* HttpServerResponse.json({ ok: true });
63 }).pipe(Effect.orDie),
64 };
65 }).pipe(Effect.provide(GCP.Storage.ReadWriteBucketHttp)),
66 );