sailfork / t3code-github / .repos/ alchemy-effect/ website/ src/ content/ docs/ gcp/ frontend/ waku.mdx

import PackageManagers from "../../../../components/PackageManagers.astro";
export const devDeps = "@alchemy.run/frontend-frameworks";

GCP.Website.Waku deploys a Waku app to Cloud Run. The React Server Components server runs in the container. Static pages are served without their extension (/about).

Install

The build integration ships separately. It only runs at deploy time, so a dev dependency is enough:

Docker has to be running when you deploy. The image is built on your machine.

Deploy the site

// alchemy.run.ts
import * as Alchemy from "alchemy";
import * as GCP from "@alchemy.run/gcp";
import * as Effect from "effect/Effect";

export const Website = GCP.Website.Waku("Website");

export default Alchemy.Stack(
  "MySite",
  { providers: GCP.providers(), state: GCP.state() },
  Effect.gen(function* () {
    const site = yield* Website;
    return { url: site.url };
  }),
);

Run alchemy deploy. site.url is the Cloud Run service URL.

Pass environment variables

// alchemy.run.ts
-export const Website = GCP.Website.Waku("Website");
+export const Website = GCP.Website.Waku("Website", {
+  env: {
+    GREETING: "Hello from Cloud Run!",
+  },
+});

Server code reads the value from process.env.GREETING.

Configure Waku

Your waku.config.* loads as-is. The waku prop overrides srcDir, distDir, or basePath for a deploy:

export const Website = GCP.Website.Waku("Website", {
  waku: { basePath: "/app/" },
});

Tune Cloud Run

export const Website = GCP.Website.Waku("Website", {
  scaling: { minInstanceCount: 1 },
  resources: { limits: { cpu: "1", memory: "1Gi" } },
});

One warm instance means no cold start for the first visitor. See Websites for the other settings.

Local development

alchemy dev runs the framework's dev server with hot reload and creates nothing in the cloud. Wrap the site in Alchemy.remote() to deploy it for real during dev.

Where next