The best way to control Claude Code, Codex and more from any computer or phone

main
mdx 131 lines 3.25 KB
Raw
1 ---
2 title: Astro
3 description: Deploy an Astro site to Cloud Run with GCP.Website.Astro — server-rendered pages, prerendered pages, and Astro's own dev server under alchemy dev.
4 sidebar:
5 order: 11
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks";
11
12 `GCP.Website.Astro` deploys an [Astro](https://astro.build) project to
13 Cloud Run. Pages render on the server by default. Pages that
14 `export const prerender = true`, and everything in `public/`, are
15 served as static files from the same container.
16
17 ## Install
18
19 The build integration ships separately. It only runs at deploy time,
20 so a dev dependency is enough:
21
22 <PackageManagers dev={devDeps} />
23
24 Docker has to be running when you deploy. The image is built on your
25 machine.
26
27 ## Deploy the site
28
29 ```typescript
30 // alchemy.run.ts
31 import * as Alchemy from "alchemy";
32 import * as GCP from "@alchemy.run/gcp";
33 import * as Effect from "effect/Effect";
34
35 export const Website = GCP.Website.Astro("Website");
36
37 export default Alchemy.Stack(
38 "MySite",
39 { providers: GCP.providers(), state: GCP.state() },
40 Effect.gen(function* () {
41 const site = yield* Website;
42 return { url: site.url };
43 }),
44 );
45 ```
46
47 Run `alchemy deploy`. `site.url` is the Cloud Run service URL.
48
49 ## Pass environment variables
50
51 ```diff lang="typescript"
52 // alchemy.run.ts
53 -export const Website = GCP.Website.Astro("Website");
54 +export const Website = GCP.Website.Astro("Website", {
55 + env: {
56 + GREETING: "Hello from Cloud Run!",
57 + },
58 +});
59 ```
60
61 Server-rendered pages read it from `process.env`:
62
63 ```astro
64 ---
65 // src/pages/index.astro
66 const greeting = process.env.GREETING ?? "hello";
67 ---
68
69 <h1>{greeting}</h1>
70 ```
71
72 ## Configure Astro
73
74 Your `astro.config.*` loads as-is: integrations, Vite plugins, and
75 everything else. Don't add an adapter. Alchemy supplies its own.
76
77 ```typescript
78 // astro.config.ts
79 import tailwindcss from "@tailwindcss/vite";
80 import { defineConfig } from "astro/config";
81
82 export default defineConfig({
83 vite: { plugins: [tailwindcss()] },
84 });
85 ```
86
87 The `astro` prop overrides a few options per deploy, such as `site`,
88 `base`, and `output`.
89
90 ## Fully static sites
91
92 With `output: "static"` every page is built ahead of time:
93
94 ```typescript
95 export const Website = GCP.Website.Astro("Website", {
96 astro: { output: "static" },
97 assets: { notFoundHandling: "404-page" },
98 });
99 ```
100
101 `404-page` serves your built `404.html` for unknown paths.
102
103 ## Tune Cloud Run
104
105 ```typescript
106 export const Website = GCP.Website.Astro("Website", {
107 scaling: { minInstanceCount: 1 },
108 resources: { limits: { cpu: "1", memory: "1Gi" } },
109 });
110 ```
111
112 One warm instance means no cold start for the first visitor. See
113 [Websites](/gcp/frontend/websites#tune-cloud-run) for the other
114 settings.
115
116 ## Local development
117
118 `alchemy dev` runs the framework's dev server with hot reload and
119 creates nothing in the cloud. Wrap the site in `Alchemy.remote()` to
120 deploy it for real during dev.
121
122 ## Example
123
124 [`examples/gcp-website-astro`](https://github.com/alchemy-run/alchemy/tree/main/examples/gcp-website-astro)
125 has a server-rendered page, a prerendered page, Tailwind, and a live
126 test.
127
128 ## Where next
129
130 - [Websites](/gcp/frontend/websites) — the settings every site shares.
131 - [Website reference](/providers/gcp/website#astro) — every prop.