1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import { serveProbes } from "../../bindingHost.ts";
4
5const IMAGE = "us-docker.pkg.dev/cloudrun/container/hello";
6const WORKER_IMAGE = "us-docker.pkg.dev/cloudrun/container/worker-pool";
7
8/** Service `GetService` reads (roles/run.viewer). */
9export const Api = GCP.Run.Service("Api", {
10 location: "us-central1",
11 template: { containers: [{ image: IMAGE }] },
12});
13
14/** Private service `InvokeService` calls (roles/run.invoker). */
15export const Callee = GCP.Run.Service("Callee", {
16 location: "us-central1",
17 template: { containers: [{ image: IMAGE }] },
18});
19
20/** Worker pool `GetWorkerPool` reads (roles/run.viewer). */
21export const Workers = GCP.Run.WorkerPool("Workers", {
22 location: "us-central1",
23 template: { containers: [{ image: WORKER_IMAGE }] },
24});
25
26/** Job `RunJob` executes (roles/run.jobsExecutorWithOverrides). */
27export const Migrate = GCP.Run.Job("Migrate", {
28 location: "us-central1",
29 containers: [{ image: "us-docker.pkg.dev/cloudrun/container/job:latest" }],
30});
31
32/**
33 * Effect-native Cloud Run service exercising every Cloud Run binding as its
34 * own runtime service account. Deployed from {@link ../Bindings.test.ts}.
35 */
36export default class RunBindingsHost extends GCP.Function<RunBindingsHost>()(
37 "RunBindingsHost",
38 { main: import.meta.url, location: "us-central1", invokerIamDisabled: true },
39 Effect.gen(function* () {
40 const getService = yield* GCP.Run.GetService(Api);
41 const getWorkerPool = yield* GCP.Run.GetWorkerPool(Workers);
42 const runJob = yield* GCP.Run.RunJob(Migrate);
43 const callee = yield* GCP.Run.InvokeService(Callee);
44
45 return {
46 fetch: serveProbes({
47 getService: getService(),
48 getWorkerPool: getWorkerPool(),
49 runJob: runJob(),
50 invokeService: Effect.gen(function* () {
51 const response = yield* callee.fetch("/");
52 return { status: response.status, text: yield* response.text };
53 }),
54 }),
55 };
56 }).pipe(
57 Effect.provide(GCP.Run.GetServiceHttp),
58 Effect.provide(GCP.Run.GetWorkerPoolHttp),
59 Effect.provide(GCP.Run.RunJobHttp),
60 Effect.provide(GCP.Run.InvokeServiceHttp),
61 ),
62) {}