| 1 | import * as AWS from "@/AWS"; |
| 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( |
| 14 | "apprunner-service", |
| 15 | import.meta.filename, |
| 16 | ); |
| 17 | |
| 18 | /** |
| 19 | * Minimal Effect-native `AWS.AppRunner.Service` served from an isolated |
| 20 | * project. `/health` answering 200 proves the generated bootstrap booted — |
| 21 | * with its imports left external the container dies at module load and App |
| 22 | * Runner never reaches RUNNING. |
| 23 | */ |
| 24 | export default class IsolatedProjectService extends AWS.AppRunner.Service<IsolatedProjectService>()( |
| 25 | "AppRunnerIsolatedProjectService", |
| 26 | { |
| 27 | main: project.main, |
| 28 | serviceName: "alchemy-test-apprunner-isolated-project", |
| 29 | port: 3000, |
| 30 | instanceConfiguration: { cpu: "256", memory: "512" }, |
| 31 | healthCheckConfiguration: { protocol: "HTTP", path: "/health" }, |
| 32 | // Docker Hub's `oven/bun` image; the public.ecr.aws default mirror |
| 33 | // aggressively rate-limits anonymous pulls (429) during local builds. |
| 34 | docker: { base: "oven/bun:1" }, |
| 35 | }, |
| 36 | Effect.gen(function* () { |
| 37 | return { |
| 38 | fetch: Effect.gen(function* () { |
| 39 | const request = yield* HttpServerRequest; |
| 40 | const url = new URL(request.url, "http://service"); |
| 41 | if (url.pathname === "/health") { |
| 42 | return yield* HttpServerResponse.json({ ok: true }); |
| 43 | } |
| 44 | return HttpServerResponse.text("hello from isolated project"); |
| 45 | }), |
| 46 | }; |
| 47 | }), |
| 48 | ) {} |