| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Output from "@/Output.ts"; |
| 4 | |
| 5 | export const publicationApplications = (contexts: { |
| 6 | shared: string; |
| 7 | other: string; |
| 8 | changed: string; |
| 9 | }) => |
| 10 | Effect.gen(function* () { |
| 11 | const first = yield* Cloudflare.Container("PublicationFirst", { |
| 12 | context: contexts.shared, |
| 13 | env: { SLOT: "first" }, |
| 14 | maxInstances: 2, |
| 15 | }).Application; |
| 16 | const second = yield* Cloudflare.Container("PublicationSecond", { |
| 17 | context: contexts.shared, |
| 18 | env: { SLOT: "second" }, |
| 19 | maxInstances: 3, |
| 20 | }).Application; |
| 21 | const other = yield* Cloudflare.Container("PublicationOtherContext", { |
| 22 | context: contexts.other, |
| 23 | maxInstances: 2, |
| 24 | }).Application; |
| 25 | const changed = yield* Cloudflare.Container("PublicationChangedContent", { |
| 26 | context: contexts.changed, |
| 27 | maxInstances: 2, |
| 28 | }).Application; |
| 29 | return { first, second, other, changed }; |
| 30 | }); |
| 31 | |
| 32 | export const sharedApplication = (context: string, repository?: string) => |
| 33 | Effect.gen(function* () { |
| 34 | const app = yield* Cloudflare.Container("SharedPublication", { |
| 35 | context, |
| 36 | publish: repository === undefined ? undefined : { repository }, |
| 37 | maxInstances: 2, |
| 38 | }).Application; |
| 39 | return { app }; |
| 40 | }); |
| 41 | |
| 42 | export const historyApplications = (converge = false) => |
| 43 | Effect.gen(function* () { |
| 44 | const target = converge |
| 45 | ? yield* Cloudflare.Container("HistoryTarget", { |
| 46 | image: "docker.io/alpine:3.19", |
| 47 | }).Application |
| 48 | : undefined; |
| 49 | const image = target?.configuration.pipe( |
| 50 | Output.map((configuration) => configuration.image), |
| 51 | ); |
| 52 | const first = yield* Cloudflare.Container("HistoryFirst", { |
| 53 | image: image ?? "alpine:3.19", |
| 54 | }).Application; |
| 55 | const second = yield* Cloudflare.Container("HistorySecond", { |
| 56 | image: image ?? "alpine:3.20", |
| 57 | }).Application; |
| 58 | return { first, second, target }; |
| 59 | }); |
| 60 | |
| 61 | export const recoveryApplications = (delay: number, includeSecond = false) => |
| 62 | Effect.gen(function* () { |
| 63 | const props = { |
| 64 | dockerfile: { |
| 65 | content: `FROM alpine:3.19\nRUN sleep ${delay}\nCMD ["sleep", "3600"]\n`, |
| 66 | }, |
| 67 | maxInstances: 2, |
| 68 | }; |
| 69 | const first = yield* Cloudflare.Container("RecoveryFirst", props) |
| 70 | .Application; |
| 71 | const second = includeSecond |
| 72 | ? yield* Cloudflare.Container("RecoverySecond", props).Application |
| 73 | : undefined; |
| 74 | return { first, second }; |
| 75 | }); |