| 1 | # GCP Website: Astro |
| 2 | |
| 3 | Deploys an [Astro](https://astro.build) site to Google Cloud with |
| 4 | `GCP.Website.Astro`. You don't need an `astro.config.*` adapter or a |
| 5 | Dockerfile. Alchemy builds the site with Astro's Node target and bakes the |
| 6 | server plus the client assets into a Node image. It pushes the image to |
| 7 | Artifact Registry and runs it on a public Cloud Run service. |
| 8 | |
| 9 | - `src/pages/index.astro` is server-rendered in the Cloud Run container on |
| 10 | every request and reads the `GREETING` environment value declared in |
| 11 | `alchemy.run.ts`. |
| 12 | - `src/pages/about.astro` opts into prerendering |
| 13 | (`export const prerender = true`) and is served as a static file. |
| 14 | - Everything under `public/` is served as static assets. |
| 15 | |
| 16 | The integration package must be installed in the project (it is loaded |
| 17 | dynamically at deploy time): |
| 18 | |
| 19 | ```sh |
| 20 | bun add -d @alchemy.run/frontend-frameworks |
| 21 | ``` |
| 22 | |
| 23 | ## Deploy |
| 24 | |
| 25 | Credentials come from your alchemy profile: run `alchemy profile` once and |
| 26 | pick GCP (*Service account JSON* for a key file, or *Stored* for an access |
| 27 | token or key kept in `~/.alchemy/credentials`, plus a default region), then |
| 28 | deploy with `--profile <name>`. The service runs in the profile's region. |
| 29 | |
| 30 | Docker must be running, because the image is built locally. |
| 31 | |
| 32 | From the repository root: |
| 33 | |
| 34 | ```sh |
| 35 | pnpm install |
| 36 | cd examples/gcp-website-astro |
| 37 | pnpm deploy --profile <name> |
| 38 | ``` |
| 39 | |
| 40 | The `url` output is the Cloud Run service URL |
| 41 | (`https://….run.app`). Unchanged sources skip the Astro build and the |
| 42 | image push on later deploys, because the input files are content-hashed |
| 43 | (scoped by `memo.include`). |
| 44 | |
| 45 | ## Local development |
| 46 | |
| 47 | ```sh |
| 48 | pnpm dev --profile <name> |
| 49 | ``` |
| 50 | |
| 51 | `alchemy dev` runs Astro's own dev server with hot reload. It creates no |
| 52 | Cloud Run service or image. |
| 53 | |
| 54 | ## Live test |
| 55 | |
| 56 | ```sh |
| 57 | ALCHEMY_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 |
| 61 | server-rendered home page, the prerendered page, the Tailwind build, and a |
| 62 | file from `public/`. At the end it destroys the stack. |
| 63 | |
| 64 | ## Destroy |
| 65 | |
| 66 | ```sh |
| 67 | pnpm destroy --profile <name> |
| 68 | ``` |
| 69 | |
| 70 | This deletes the Cloud Run service, its Artifact Registry image repository, |
| 71 | and the service account Alchemy minted for it. |