Cloudflare Pages Deployment for Terraphim AI Documentation
This document describes how to deploy the Terraphim AI documentation to Cloudflare Pages at https://docs.terraphim.ai.
Overview
The documentation is built using mdBook and deployed to Cloudflare Pages with secrets managed via 1Password. The migration from Netlify to Cloudflare Pages provides:
- Global CDN: Content served from 200+ edge locations
- Automatic SSL: Free SSL certificates with automatic renewal
- Preview deployments: Automatic previews for pull requests
- Fast builds: Quick build and deployment times
- Security headers: Built-in security headers configuration
Prerequisites
For Local Development
- Install mdBook:
- Install mdBook Mermaid plugin (optional, for diagrams):
- Install Wrangler CLI:
- Authenticate with Cloudflare:
For CI/CD (GitHub Actions)
The workflow uses 1Password for secret management. Configure the following:
-
GitHub Secret:
OP_SERVICE_ACCOUNT_TOKEN: Your 1Password service account token
-
1Password Vault (TerraphimPlatform): The workflow automatically reads from:
op://TerraphimPlatform/terraphim-md-book-cloudflare/workers-api-tokenop://TerraphimPlatform/terraphim-md-book-cloudflare/account-idop://TerraphimPlatform/terraphim-md-book-cloudflare/zone-id
-
Setup 1Password Service Account:
# Create service account with vault access
# See: https://developer.1password.com/docs/service-accounts/Local Development
Build Documentation
The built documentation will be in docs/book/.
Serve Locally
This starts a local server at http://localhost:3000.
Watch for Changes
The serve command automatically watches for changes and rebuilds.
Deployment
Automatic Deployment (GitHub Actions)
The documentation is automatically deployed when:
-
Production (https://docs.terraphim.ai):
- Push to
mainbranch with changes indocs/ - Secrets are loaded from 1Password automatically
- Push to
-
Preview:
- Pull requests with changes in
docs/ - Preview URL is automatically commented on the PR
- Pull requests with changes in
-
Manual:
- Trigger via GitHub Actions workflow dispatch
Manual Deployment with 1Password
First, set up 1Password integration:
# Run setup script
Then deploy using 1Password credentials:
# Deploy with 1Password (recommended)
# Or manually export credentials
Or use Wrangler directly:
# Build
# Deploy to preview
# Deploy to production
Configuration
wrangler.toml
The docs/wrangler.toml file configures:
- Project name and compatibility
- Security headers
- Cache control rules
- Redirects
book.toml
The docs/book.toml file configures mdBook:
- Book metadata (title, authors)
- Output settings
- Preprocessors (Mermaid)
- Additional JavaScript files
Custom Domain Setup
- Go to Cloudflare Dashboard > Pages > terraphim-docs > Custom domains
- Add
docs.terraphim.ai - Follow DNS configuration instructions
- SSL certificate is automatically provisioned
Monitoring
Cloudflare Dashboard
- Analytics: View page views, unique visitors, bandwidth
- Functions: Monitor any edge functions
- Deployments: View deployment history and rollback if needed
GitHub Actions
- Check workflow runs in Actions tab
- View deployment summaries
- Debug failed deployments
Troubleshooting
Build Failures
- Missing preprocessor:
- Broken links:
| - Syntax errors in SUMMARY.md:
Verify all links in
docs/src/SUMMARY.mdare valid.
Deployment Failures
- Authentication issues:
-
Missing secrets: Ensure GitHub secrets are configured
-
Project doesn't exist: Create the project first in Cloudflare Dashboard
Cache Issues
Clear the Cloudflare cache:
# Via API
# Via Dashboard
# Cloudflare Dashboard > Caching > Configuration > Purge EverythingMigration from Netlify
The migration involves:
- Removing Netlify configuration (if any)
- Adding Cloudflare Pages configuration (wrangler.toml)
- Setting up GitHub Actions (deploy-docs.yml)
- Configuring DNS (point doc.terraphim.ai to Cloudflare)
- Testing deployment pipeline
File Structure
terraphim-ai/
βββ docs/
β βββ book.toml # mdBook configuration
β βββ wrangler.toml # Cloudflare Pages configuration
β βββ .env.example # Environment variable template
β βββ .env.1password # 1Password environment file (generated)
β βββ CLOUDFLARE_DEPLOYMENT.md # This file
β βββ src/
β βββ SUMMARY.md # Table of contents
β βββ *.md # Documentation pages
βββ scripts/
β βββ deploy-docs.sh # Manual deployment script
β βββ setup-1password-cloudflare.sh # 1Password setup script
βββ .github/
βββ workflows/
βββ deploy-docs.yml # CI/CD workflow (uses 1Password)Security Considerations
- Secrets are stored in 1Password, not in GitHub or plaintext files
- 1Password service accounts have minimal vault access
- API tokens should have minimal permissions (Pages Edit only)
- Use GitHub Environments with protection rules for production
- Review preview deployments before merging to main
- Security headers are configured in wrangler.toml
- Never commit
.envfiles (excluded in .gitignore)
Performance Optimization
- Static assets (CSS, JS, images) cached for 1 year
- HTML pages have
must-revalidatefor instant updates - Cloudflare's global CDN provides low-latency access
- Automatic compression (gzip, brotli)
Cost
Cloudflare Pages is free for:
- Unlimited sites
- Unlimited bandwidth
- 500 builds per month
- 1 concurrent build (free tier)
This is more generous than Netlify's free tier for most use cases.