1# GCP Website: Next.js
2
3Deploys a [Next.js](https://nextjs.org) app to Google Cloud with
4`GCP.Website.Nextjs`. There is no OpenNext and no Dockerfile. Alchemy runs
5`next build`, then bakes `.next/`, `public/`, `next.config.mjs`, and a
6small `next({ dev: false })` server into a Node image, with `next`,
7`react`, and `react-dom` installed into it. It pushes the image to Artifact
8Registry and runs it on a public Cloud Run service.
9
10- `app/page.jsx` is `force-dynamic`, so it is server-rendered in the Cloud
11 Run container on every request and reads the `GREETING` environment
12 value declared in `alchemy.run.ts`.
13- `app/api/hello/route.ts` is an App Router route handler.
14- Everything under `public/` is served as static assets. Tailwind compiles
15 through the project's own `postcss.config.mjs`.
16
17The integration package must be installed in the project (it is loaded
18dynamically at deploy time):
19
20```sh
21bun add -d @alchemy.run/frontend-frameworks
22```
23
24## Deploy
25
26Credentials come from your alchemy profile: run `alchemy profile` once and
27pick GCP (*Service account JSON* for a key file, or *Stored* for an access
28token or key kept in `~/.alchemy/credentials`, plus a default region), then
29deploy with `--profile <name>`. The service runs in the profile's region.
30
31Docker must be running, because the image is built locally.
32
33From the repository root:
34
35```sh
36pnpm install
37cd examples/gcp-website-nextjs
38pnpm deploy --profile <name>
39```
40
41The `url` output is the Cloud Run service URL (`https://….run.app`).
42Unchanged sources skip `next build` and the image push on later deploys,
43because the input files are content-hashed (scoped by `memo.include`).
44
45## Local development
46
47```sh
48pnpm dev --profile <name>
49```
50
51`alchemy dev` runs `next dev` with hot reload. It creates no Cloud Run
52service or image.
53
54## Live test
55
56```sh
57ALCHEMY_PROFILE=<name> bun test test/integ.test.ts --timeout 1200000
58```
59
60[The test](./test/integ.test.ts) deploys the stack and checks the
61server-rendered home page, the API route, the compiled Tailwind stylesheet,
62and a file from `public/`. At the end it destroys the stack.
63
64## Destroy
65
66```sh
67pnpm destroy --profile <name>
68```
69
70This deletes the Cloud Run service, its Artifact Registry image repository,
71and the service account Alchemy minted for it.