| 1 | import * as Docker from "@/Docker"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import { isolatedProject } from "../../IsolatedProject.ts"; |
| 6 | |
| 7 | /** |
| 8 | * The isolated consumer project this service is bundled from (see |
| 9 | * `test/IsolatedProject.ts`): `main` lives outside the repository, so the |
| 10 | * bundle `cwd` resolves none of alchemy's dependencies and the bun |
| 11 | * bootstrap's own imports must be anchored by the bundler. |
| 12 | */ |
| 13 | export const project = isolatedProject("docker-service", import.meta.filename); |
| 14 | |
| 15 | /** |
| 16 | * Fixed host port published through the swarm ingress. Deterministic and |
| 17 | * distinct from the other Docker suites on the shared local daemon. |
| 18 | */ |
| 19 | export const SERVICE_EXTERNAL_PORT = 43119; |
| 20 | |
| 21 | /** |
| 22 | * Minimal effectful `Docker.Service` served from an isolated project. |
| 23 | * `/health` answering 200 proves the generated bootstrap booted — with its |
| 24 | * imports left external bun dies at module load and the swarm task |
| 25 | * restart-loops without ever listening. |
| 26 | */ |
| 27 | export default class IsolatedProjectService extends Docker.Service<IsolatedProjectService>()( |
| 28 | "DockerIsolatedProjectService", |
| 29 | { |
| 30 | main: project.main, |
| 31 | port: 3000, |
| 32 | ports: [{ external: SERVICE_EXTERNAL_PORT, internal: 3000 }], |
| 33 | replicas: 1, |
| 34 | }, |
| 35 | Effect.gen(function* () { |
| 36 | return { |
| 37 | fetch: Effect.gen(function* () { |
| 38 | const request = yield* HttpServerRequest; |
| 39 | const url = new URL(request.url, "http://service"); |
| 40 | if (url.pathname === "/health") { |
| 41 | return yield* HttpServerResponse.json({ ok: true }); |
| 42 | } |
| 43 | return HttpServerResponse.text("hello from isolated project"); |
| 44 | }), |
| 45 | }; |
| 46 | }), |
| 47 | ) {} |