Open History to see the last commit
1/**
2 * The Git host with its pack hasher on AWS Lambda (DESIGN §22.11): the
3 * same building-block assembly as `stack.ts`, with `HasherLambda` in place
4 * of the in-process hasher. Needs BOTH provider sets — the Worker binds
5 * `InvokeFunction` cross-cloud (an IAM identity is minted for it).
6 */
7import * as AWS from "@alchemy.run/aws";
8import * as Cloudflare from "@alchemy.run/cloudflare";
9import {
10 BlobStoreR2,
11 GIT_WORKER_OPTIONS,
12 ApiHandlersLive,
13 ReposDurableObject,
14 RegistryDurableObject,
15} from "@alchemy.run/git";
16import { HasherFunction, HasherLambda } from "@alchemy.run/git/Hasher";
17import * as Alchemy from "alchemy";
18import * as Effect from "effect/Effect";
19import * as HttpRouter from "effect/http/HttpRouter";
20import * as Layer from "effect/Layer";
21import { TestRoutes } from "./http.ts";
22import { TEST_SECRET, TestApi, TestAuthLive } from "./stack.ts";
23export { TEST_SECRET };
24
25const GitObjects = Cloudflare.R2.Bucket("GitLambdaObjects", {
26 forceDestroy: true,
27});
28
29const GitLive = TestRoutes.pipe(
30 Layer.provide(ApiHandlersLive),
31 Layer.provide(ReposDurableObject),
32 Layer.provide(RegistryDurableObject),
33 Layer.provide(HasherLambda(HasherFunction)),
34 Layer.provide(AWS.Lambda.InvokeFunctionHttp),
35 Layer.provide(BlobStoreR2(GitObjects)),
36);
37
38export default class LambdaGitHost extends Cloudflare.Worker<LambdaGitHost>()(
39 "GitLambdaWorker",
40 {
41 main: import.meta.url,
42 ...GIT_WORKER_OPTIONS,
43 observability: { enabled: true },
44 },
45 Effect.gen(function* () {
46 const fetch = yield* HttpRouter.toHttpEffect(GitLive);
47 return { fetch };
48 }).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
49) {}
50
51export const makeLambdaTestStack = (name: string) =>
52 Alchemy.Stack(
53 name,
54 {
55 providers: Layer.mergeAll(AWS.providers(), Cloudflare.providers()),
56 state: Cloudflare.state(),
57 },
58 Effect.gen(function* () {
59 const host = yield* LambdaGitHost;
60 return { url: host.url.as<string>() };
61 }),
62 );