|
1 | 1 | # Website Deployment |
2 | 2 |
|
3 | | -This document describes the deployment configuration for the pgflow documentation website. |
| 3 | +The pgflow documentation website is deployed to **Cloudflare Pages** via GitHub Actions. |
4 | 4 |
|
5 | | -## Deployment Target |
6 | | - |
7 | | -The website is deployed to **Cloudflare Pages** via GitHub Actions workflow. |
8 | | - |
9 | | -- **Production URL**: https://www.pgflow.dev |
10 | | -- **Preview URLs**: https://pr-{number}.pgflow.pages.dev (for pull requests) |
| 5 | +- **Production**: https://www.pgflow.dev |
| 6 | +- **Preview**: https://pr-{number}.pgflow.pages.dev |
11 | 7 |
|
12 | 8 | ## Required GitHub Secrets |
13 | 9 |
|
14 | | -The following secrets must be configured in the GitHub repository (Settings → Secrets and variables → Actions). |
15 | | - |
16 | | -**Note**: Some secrets are namespaced (e.g., `WEBSITE_*`) at the GitHub level but are mapped to simpler names (e.g., `VITE_*`, `PLAUSIBLE_PROXY_URL`) when passed as environment variables to the build process. |
17 | | - |
18 | | -### Cloudflare Configuration |
19 | | - |
20 | | -- **`CLOUDFLARE_API_TOKEN`** |
21 | | - - **GitHub Secret Name**: `CLOUDFLARE_API_TOKEN` |
22 | | - - **Environment variable**: `CLOUDFLARE_API_TOKEN` |
23 | | - - API token for deploying to Cloudflare Pages |
24 | | - |
25 | | -- **`CLOUDFLARE_ACCOUNT_ID`** |
26 | | - - **GitHub Secret Name**: `CLOUDFLARE_ACCOUNT_ID` |
27 | | - - **Environment variable**: `CLOUDFLARE_ACCOUNT_ID` |
28 | | - - Cloudflare account ID |
29 | | - |
30 | | -### Supabase Configuration |
31 | | - |
32 | | -Website deployment requires Supabase configuration for both preview and production environments: |
| 10 | +Configure these in repository Settings → Secrets and variables → Actions. |
33 | 11 |
|
34 | | -**Preview Environment:** |
35 | | -- **`WEBSITE_PREVIEW_SUPABASE_URL`** |
36 | | - - **GitHub Secret Name**: `WEBSITE_PREVIEW_SUPABASE_URL` |
37 | | - - **Maps to environment variable**: `VITE_SUPABASE_URL` (in preview deployments) |
38 | | - - Supabase project URL for preview deployments |
| 12 | +### Cloudflare |
| 13 | +- `CLOUDFLARE_API_TOKEN` - API token for Cloudflare Pages deployment |
| 14 | +- `CLOUDFLARE_ACCOUNT_ID` - Cloudflare account ID |
39 | 15 |
|
40 | | -- **`WEBSITE_PREVIEW_SUPABASE_ANON_KEY`** |
41 | | - - **GitHub Secret Name**: `WEBSITE_PREVIEW_SUPABASE_ANON_KEY` |
42 | | - - **Maps to environment variable**: `VITE_SUPABASE_ANON_KEY` (in preview deployments) |
43 | | - - Supabase anonymous key for preview deployments |
| 16 | +### Supabase |
44 | 17 |
|
45 | | -**Production Environment:** |
46 | | -- **`WEBSITE_PRODUCTION_SUPABASE_URL`** |
47 | | - - **GitHub Secret Name**: `WEBSITE_PRODUCTION_SUPABASE_URL` |
48 | | - - **Maps to environment variable**: `VITE_SUPABASE_URL` (in production deployments) |
49 | | - - Supabase project URL for production |
| 18 | +**Preview:** |
| 19 | +- `WEBSITE_PREVIEW_SUPABASE_URL` → `VITE_SUPABASE_URL` |
| 20 | +- `WEBSITE_PREVIEW_SUPABASE_ANON_KEY` → `VITE_SUPABASE_ANON_KEY` |
50 | 21 |
|
51 | | -- **`WEBSITE_PRODUCTION_SUPABASE_ANON_KEY`** |
52 | | - - **GitHub Secret Name**: `WEBSITE_PRODUCTION_SUPABASE_ANON_KEY` |
53 | | - - **Maps to environment variable**: `VITE_SUPABASE_ANON_KEY` (in production deployments) |
54 | | - - Supabase anonymous key for production |
| 22 | +**Production:** |
| 23 | +- `WEBSITE_PRODUCTION_SUPABASE_URL` → `VITE_SUPABASE_URL` |
| 24 | +- `WEBSITE_PRODUCTION_SUPABASE_ANON_KEY` → `VITE_SUPABASE_ANON_KEY` |
55 | 25 |
|
56 | | -### Analytics Configuration |
| 26 | +### Analytics |
| 27 | +- `WEBSITE_PLAUSIBLE_PROXY_URL` → `PLAUSIBLE_PROXY_URL` (required for production only) |
| 28 | + - Cloudflare Workers proxy URL for Plausible Analytics |
| 29 | + - Example: `https://your-worker.your-username.workers.dev` |
| 30 | + - Proxies requests to avoid ad blockers |
57 | 31 |
|
58 | | -- **`WEBSITE_PLAUSIBLE_PROXY_URL`** - Cloudflare Workers proxy URL for Plausible Analytics (website-specific) |
59 | | - - **GitHub Secret Name**: `WEBSITE_PLAUSIBLE_PROXY_URL` |
60 | | - - **Maps to environment variable**: `PLAUSIBLE_PROXY_URL` (used in `astro.config.mjs`) |
61 | | - - Example value: `https://your-worker-name.your-username.workers.dev` |
62 | | - - This proxies requests to Plausible to avoid ad blockers |
63 | | - - If this URL becomes invalid, Plausible tracking will stop working |
64 | | - - Note: This is separate from demo app analytics which uses its own proxy URL |
| 32 | +### Deployment Environment |
| 33 | +- `DEPLOYMENT_ENV` - Set automatically by workflow (`production` or `preview`) |
| 34 | + - Controls robots.txt and validates production requirements |
| 35 | + - Not set for build/test jobs (safe defaults apply) |
65 | 36 |
|
66 | 37 | ## Deployment Workflow |
67 | 38 |
|
68 | | -The deployment is handled by the `deploy-website` job in `.github/workflows/ci.yml`: |
| 39 | +The `deploy-website` job in `.github/workflows/ci.yml`: |
69 | 40 |
|
70 | | -1. **Trigger**: Runs on push to `main` or when a pull request is opened/updated |
71 | | -2. **Affected Check**: Only deploys if the website package is affected by changes (using Nx) |
72 | | -3. **Build**: Builds the website with environment variables injected |
73 | | -4. **Deploy**: |
74 | | - - Production: Deploys to main branch on Cloudflare Pages |
75 | | - - Preview: Deploys to PR-specific branch on Cloudflare Pages |
| 41 | +1. Triggers on push to `main` or PR updates |
| 42 | +2. Checks if website is affected (Nx) |
| 43 | +3. Sets `DEPLOYMENT_ENV` based on branch |
| 44 | +4. Builds with injected environment variables |
| 45 | + - Production: Requires `PLAUSIBLE_PROXY_URL`, enables indexing |
| 46 | + - Preview: Optional `PLAUSIBLE_PROXY_URL`, blocks indexing |
| 47 | +5. Deploys to Cloudflare Pages |
76 | 48 |
|
77 | 49 | ## Local Development |
78 | 50 |
|
79 | | -For local development, the Plausible proxy URL falls back to a hardcoded value in `astro.config.mjs` if the `PLAUSIBLE_PROXY_URL` environment variable is not set. |
80 | | - |
81 | | -To test with a specific proxy URL locally: |
| 51 | +No environment variables required. Optional overrides: |
82 | 52 |
|
83 | 53 | ```bash |
| 54 | +# With custom proxy |
84 | 55 | PLAUSIBLE_PROXY_URL=https://your-worker.your-username.workers.dev pnpm nx dev website |
| 56 | + |
| 57 | +# Test production behavior |
| 58 | +DEPLOYMENT_ENV=production PLAUSIBLE_PROXY_URL=https://your-worker.your-username.workers.dev pnpm nx dev website |
85 | 59 | ``` |
86 | 60 |
|
87 | 61 | ## Troubleshooting |
88 | 62 |
|
89 | | -### Plausible Analytics Not Tracking |
90 | | - |
91 | | -If Plausible stops tracking visitors: |
92 | | - |
93 | | -1. Check if the Cloudflare Workers proxy URL is accessible: |
94 | | - ```bash |
95 | | - curl -I https://your-worker-name.your-username.workers.dev/assets/script.hash.outbound-links.pageview-props.tagged-events.js |
96 | | - ``` |
97 | | - |
98 | | -2. If the URL fails (DNS resolution error or 404), update the `WEBSITE_PLAUSIBLE_PROXY_URL` secret in GitHub with the correct URL |
99 | | - |
100 | | -3. The proxy URL may change if the Cloudflare Workers username changes |
101 | | - |
102 | | -4. After updating the secret, redeploy the website (push to `main` or re-run the workflow) |
103 | | - |
104 | | -### Deployment Fails |
| 63 | +**Analytics not tracking:** |
| 64 | +- Verify proxy URL: `curl -I https://your-worker.your-username.workers.dev/assets/script...js` |
| 65 | +- Update `WEBSITE_PLAUSIBLE_PROXY_URL` secret if needed |
| 66 | +- Redeploy website |
105 | 67 |
|
106 | | -- Verify all required secrets are configured in GitHub |
107 | | -- Check the GitHub Actions workflow logs for specific error messages |
108 | | -- Ensure the Cloudflare API token has the necessary permissions (Account → Cloudflare Pages - Edit) |
| 68 | +**Build errors:** |
| 69 | +- `DEPLOYMENT_ENV must be either 'production' or 'preview'` - Invalid value in workflow |
| 70 | +- `PLAUSIBLE_PROXY_URL required for production` - Missing `WEBSITE_PLAUSIBLE_PROXY_URL` secret |
| 71 | +- Check workflow logs for details |
| 72 | +- Verify Cloudflare API token permissions |
0 commit comments