@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 78 lines 3.09 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import * as Kubernetes from "@alchemy.run/kubernetes";
3 /**
4 * A "guestbook" app on GKE Autopilot that exercises the full Kubernetes
5 * container surface:
6 *
7 * - a stack-owned Autopilot cluster + Firestore database + a namespace
8 * applied as a raw manifest via `Kubernetes.Manifest` (`src/infra.ts`),
9 * - `Api` — an effectful `Kubernetes.Deployment` (bundled `main:` image source)
10 * behind an external Network Load Balancer, with a Firestore binding
11 * granted to its Kubernetes ServiceAccount's Workload Identity principal,
12 * plus the typed `podTemplate` escape hatch (`src/Api.ts`),
13 * - `Web` — an EXTERNAL `Kubernetes.Deployment` (registry `image:` source, no
14 * Effect runtime in the container), nginx behind its own load balancer,
15 * - `SeedJob` — an inline-effect one-shot `Kubernetes.Job` (`{ run }`) that
16 * seeds the guestbook database when the batch/v1 Job is applied on deploy
17 * (`src/SeedJob.ts`).
18 */
19 import * as Alchemy from "alchemy";
20 import * as Effect from "effect/Effect";
21 import * as Layer from "effect/Layer";
22 import ApiLive, { Api } from "./src/Api.ts";
23 import { EntriesDatabase, GuestbookCluster, GuestbookNamespace } from "./src/infra.ts";
24 import SeedJob from "./src/SeedJob.ts";
25
26 export default Alchemy.Stack(
27 "GcpGkeExample",
28 {
29 providers: Layer.mergeAll(GCP.providers(), Kubernetes.providers()),
30 state: Alchemy.localState(),
31 },
32 Effect.gen(function* () {
33 const cluster = yield* GuestbookCluster;
34 const database = yield* EntriesDatabase;
35 const ns = yield* GuestbookNamespace;
36
37 // ── Api — effectful server in the TAGGED form (bundled `main:`).
38 // `ApiLive` (the `Api.make(...)` Layer, provided below) carries the
39 // props + init program; its init declares the Firestore binding whose
40 // grant lands on the Deployment's Workload Identity principal; see
41 // src/Api.ts.
42 const api = yield* Api;
43
44 // ── Web — EXTERNAL deployment: a pre-built registry image (mirrored
45 // into Artifact Registry), no Effect runtime in the container. GKE
46 // provisions a load balancer for the LoadBalancer Service; port 80,
47 // so `web.url` carries no port suffix.
48 const web = yield* Kubernetes.Deployment("Web", {
49 cluster,
50 image: "nginx:1.27",
51 namespace: ns.name,
52 replicas: 2,
53 port: 80,
54 serviceType: "LoadBalancer",
55 resources: {
56 requests: { cpu: "250m", memory: "512Mi" },
57 limits: { cpu: "250m", memory: "512Mi" },
58 },
59 });
60
61 // ── SeedJob — inline-effect one-shot Job; runs to completion on deploy
62 // (Kubernetes runs a batch/v1 Job as soon as it is applied).
63 const seedJob = yield* SeedJob;
64
65 return {
66 clusterId: cluster.clusterId,
67 clusterName: cluster.name,
68 // Full URL including the Service port (http://<ip>:3000).
69 apiUrl: api.url,
70 webUrl: web.url,
71 databaseName: database.name,
72 namespace: ns.name,
73 apiServiceAccount: api.serviceAccountName,
74 seedJobName: seedJob.jobName,
75 seedJobServiceAccount: seedJob.serviceAccountName,
76 };
77 }).pipe(Effect.provide(ApiLive)),
78 );