Files
egfh-website/docs/cloudflare-pages.md
T
2026-06-21 05:04:26 -04:00

83 lines
2.7 KiB
Markdown

# Cloudflare Pages Direct Upload
This project uses Astro static output, so Cloudflare Pages only needs the generated `dist/` directory.
Because the source repository is hosted in Gitea, use Cloudflare Pages Direct Upload rather than Cloudflare's GitHub/GitLab integration. The build happens in your local machine, Docker container, or Gitea CI runner, then Wrangler uploads the finished files to Cloudflare.
## URL Sets
Keep three sets of URLs separate:
- Local development: `.env`, used by Docker Compose and `astro dev`.
- Test/preview deployment: `.env.pages.test`, used by `npm run build:pages:test` and `npm run deploy:pages:test`.
- Production deployment: `.env.pages.prod`, used by `npm run build:pages:prod` and `npm run deploy:pages:prod`.
The important distinction is that Astro fetches Directus content during the build. The URLs in the env file selected for the build are baked into the generated static files.
## First-Time Setup
Copy the example files and fill in the real values:
```bash
cp .env.pages.test.example .env.pages.test
cp .env.pages.prod.example .env.pages.prod
```
Do not commit `.env.pages.test` or `.env.pages.prod`; they contain API tokens.
Create a Cloudflare API token with permission to deploy Pages projects, then set these values in both env files:
```env
CF_PAGES_PROJECT_NAME=swansea-airfield
CLOUDFLARE_ACCOUNT_ID=...
CLOUDFLARE_API_TOKEN=...
```
For Directus, use public HTTPS URLs in Pages env files. Do not use Docker-only hostnames such as `http://directus:8055` outside Docker Compose.
## Build Locally For Test
```bash
npm run build:pages:test
```
This loads `.env.pages.test`, fetches content from the test Directus URL, and writes static files to `dist/`.
## Deploy To Cloudflare Test Branch
```bash
npm run deploy:pages:test
```
This builds with `.env.pages.test`, then uploads `dist/` to the `test` Pages branch. Cloudflare will serve it on the matching branch preview URL.
## Deploy To Production
```bash
npm run deploy:pages:prod
```
This builds with `.env.pages.prod`, then uploads `dist/` to the `main` Pages branch.
## Gitea CI Shape
In Gitea Actions, store the same values as CI secrets and run:
```bash
npm ci
npm run deploy:pages:prod
```
The deploy script reads from the env file first, but existing CI environment variables win. That means secrets injected by Gitea can override placeholder values from a committed example or generated env file.
## Content Updates
Static deploys are snapshots. If Directus content changes after deployment, Cloudflare Pages will not update until another build and deploy runs.
For production, trigger `npm run deploy:pages:prod` from either:
- a code push to Gitea,
- a manual Gitea Actions workflow,
- a Directus webhook that calls your CI runner,
- or a scheduled CI job.