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

main
ts 73 lines 2.9 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as Kubernetes from "@alchemy.run/kubernetes";
3 /**
4 * A "guestbook" app on EKS Auto Mode that exercises the full Kubernetes
5 * container surface:
6 *
7 * - a stack-owned network + `compute: "auto"` cluster + DynamoDB table +
8 * a namespace applied as a raw manifest via `Kubernetes.Manifest` (`src/infra.ts`),
9 * - `Api` — an effectful `Kubernetes.Deployment` (bundled `main:` image source)
10 * behind an internet-facing NLB with DynamoDB bindings on the pod-identity
11 * role, plus the typed `podTemplate` escape hatch (`src/Api.ts`),
12 * - `Web` — an EXTERNAL `Kubernetes.Deployment` (registry `image:` source, no
13 * Effect runtime in the container), nginx behind its own NLB,
14 * - `SeedJob` — an inline-effect one-shot `Kubernetes.Job` (`{ run }`) that
15 * seeds the guestbook table when the batch/v1 Job is applied on deploy
16 * (`src/SeedJob.ts`).
17 */
18 import * as Alchemy from "alchemy";
19 import * as Effect from "effect/Effect";
20 import * as Layer from "effect/Layer";
21 import ApiLive, { Api } from "./src/Api.ts";
22 import { EntriesTable, GuestbookCluster, GuestbookNamespace } from "./src/infra.ts";
23 import SeedJob from "./src/SeedJob.ts";
24
25 export default Alchemy.Stack(
26 "AwsEksExample",
27 {
28 providers: Layer.mergeAll(AWS.providers(), Kubernetes.providers()),
29 state: Alchemy.localState(),
30 },
31 Effect.gen(function* () {
32 const cluster = yield* GuestbookCluster;
33 const table = yield* EntriesTable;
34 const ns = yield* GuestbookNamespace;
35
36 // ── Api — effectful server in the TAGGED form (bundled `main:`).
37 // `ApiLive` (the `Api.make(...)` Layer, provided below) carries the
38 // props + init program; its init declares the DynamoDB bindings that
39 // land on the generated pod-identity role; see src/Api.ts.
40 const api = yield* Api;
41
42 // ── Web — EXTERNAL deployment: a pre-built registry image (mirrored
43 // into ECR), no Effect runtime in the container. Auto Mode's built-in
44 // controller provisions the NLB for the LoadBalancer Service; port 80,
45 // so `web.url` carries no port suffix.
46 const web = yield* Kubernetes.Deployment("Web", {
47 cluster,
48 image: "public.ecr.aws/nginx/nginx:1.27",
49 namespace: ns.name,
50 replicas: 2,
51 port: 80,
52 serviceType: "LoadBalancer",
53 resources: {
54 requests: { cpu: "50m", memory: "64Mi" },
55 limits: { cpu: "250m", memory: "128Mi" },
56 },
57 });
58
59 // ── SeedJob — inline-effect one-shot Job; runs to completion on deploy
60 // (Kubernetes runs a batch/v1 Job as soon as it is applied).
61 const seedJob = yield* SeedJob;
62
63 return {
64 clusterName: cluster.clusterName,
65 // Full URL including the Service port (http://<nlb-hostname>:3000).
66 apiUrl: api.url,
67 webUrl: web.url,
68 tableName: table.tableName,
69 namespace: ns.name,
70 seedJobName: seedJob.jobName,
71 };
72 }).pipe(Effect.provide(ApiLive)),
73 );