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

main
mdx 98 lines 2.45 KB
Raw
1 ---
2 title: vinext
3 description: Deploy a vinext app (the Next.js API on Vite) to Cloud Run with GCP.Website.Vinext.
4 sidebar:
5 order: 19
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks";
11
12 `GCP.Website.Vinext` deploys a [vinext](https://vinext.dev) app to
13 Cloud Run. Alchemy runs vinext's Vite build and serves it with vinext's
14 production server.
15
16 ## Install
17
18 The build integration ships separately. It only runs at deploy time,
19 so a dev dependency is enough:
20
21 <PackageManagers dev={devDeps} />
22
23 Docker has to be running when you deploy. The image is built on your
24 machine.
25
26 ## Deploy the site
27
28 ```typescript
29 // alchemy.run.ts
30 import * as Alchemy from "alchemy";
31 import * as GCP from "@alchemy.run/gcp";
32 import * as Effect from "effect/Effect";
33
34 export const Website = GCP.Website.Vinext("Website");
35
36 export default Alchemy.Stack(
37 "MySite",
38 { providers: GCP.providers(), state: GCP.state() },
39 Effect.gen(function* () {
40 const site = yield* Website;
41 return { url: site.url };
42 }),
43 );
44 ```
45
46 Run `alchemy deploy`. `site.url` is the Cloud Run service URL.
47
48 ## Pass environment variables
49
50 ```diff lang="typescript"
51 // alchemy.run.ts
52 -export const Website = GCP.Website.Vinext("Website");
53 +export const Website = GCP.Website.Vinext("Website", {
54 + env: {
55 + GREETING: "Hello from Cloud Run!",
56 + },
57 +});
58 ```
59
60 Server code reads the value from `process.env.GREETING`.
61
62 ## Share the data cache
63
64 ISR and `"use cache"` keep data in each instance's memory, which other
65 instances can't see. Point `REDIS_URL` at a Redis server to share it:
66
67 ```typescript
68 export const Website = GCP.Website.Vinext("Website", {
69 env: { REDIS_URL: "redis://10.0.0.3:6379" },
70 });
71 ```
72
73 [Memorystore](/gcp/data/memorystore) gives you a Redis server on a
74 private IP.
75
76 ## Tune Cloud Run
77
78 ```typescript
79 export const Website = GCP.Website.Vinext("Website", {
80 scaling: { minInstanceCount: 1 },
81 resources: { limits: { cpu: "1", memory: "1Gi" } },
82 });
83 ```
84
85 One warm instance means no cold start for the first visitor. See
86 [Websites](/gcp/frontend/websites#tune-cloud-run) for the other
87 settings.
88
89 ## Local development
90
91 `alchemy dev` runs the framework's dev server with hot reload and
92 creates nothing in the cloud. Wrap the site in `Alchemy.remote()` to
93 deploy it for real during dev.
94
95 ## Where next
96
97 - [Websites](/gcp/frontend/websites) — the settings every site shares.
98 - [Website reference](/providers/gcp/website#vinext) — every prop.