1import * as Cloudflare from "@/Cloudflare";
2import * as Alchemy from "@/index.ts";
3import * as Effect from "effect/Effect";
4import * as Path from "effect/Path";
5import type { AttachmentContainerObject } from "./worker.ts";
6
7export const stackName = "ContainerAttachmentStack";
8
9export const attachmentStack = (attached = true) =>
10 Alchemy.Stack(
11 stackName,
12 { providers: Cloudflare.providers(), state: Cloudflare.state() },
13 Effect.gen(function* () {
14 const path = yield* Path.Path;
15 const container = Cloudflare.Container<AttachmentContainerObject>(
16 "AttachmentContainer",
17 {
18 className: "AttachmentContainerObject",
19 image: "mendhak/http-https-echo:41",
20 maxInstances: 2,
21 },
22 );
23 const other = Cloudflare.Container<AttachmentContainerObject>(
24 "OtherAttachmentContainer",
25 {
26 className: "AttachmentContainerObject",
27 image: "mendhak/http-https-echo:41",
28 maxInstances: 2,
29 },
30 );
31 const worker = yield* Cloudflare.Worker("AttachmentWorker", {
32 main: path.join(import.meta.dirname, "worker.ts"),
33 env: attached ? { ECHO: container } : {},
34 });
35 const otherWorker = yield* Cloudflare.Worker("OtherAttachmentWorker", {
36 main: path.join(import.meta.dirname, "worker.ts"),
37 env: { ECHO: other },
38 });
39 const app = yield* container.Application;
40 const otherApp = yield* other.Application;
41 return {
42 worker,
43 app,
44 otherWorker,
45 otherApp,
46 url: worker.url.as<string>(),
47 };
48 }),
49 );
50
51export default attachmentStack();