Cloudflare Pages Deployment¶
This guide walks through deploying your AI Knowledge Base to Cloudflare Pages with Cloudflare Access protection.
Overview¶
- Hosting: Cloudflare Pages (static site hosting)
- Build: Automated from GitHub repository
- Access Control: Cloudflare Access (private URL)
- Domain: Custom domain or
*.pages.devsubdomain
Prerequisites¶
- GitHub repository with your knowledge base
- Cloudflare account (free tier is sufficient)
- Domain managed by Cloudflare (optional, for custom domain)
Step 1: Create GitHub Repository¶
First, push your local repository to GitHub:
# In your local ai-knowledge-base directory
git remote add origin https://github.com/YOUR-USERNAME/ai-knowledge-base.git
git branch -M main
git push -u origin main
Make sure your repository is:
- Private (recommended for internal knowledge base)
- Contains all files including requirements.txt, mkdocs.yml, scripts, and data
Step 2: Create Cloudflare Pages Project¶
Via Cloudflare Dashboard¶
- Log in to Cloudflare Dashboard
- Go to Pages in the left sidebar
- Click Create a project
- Choose Connect to Git
- Select your GitHub account and repository
- Choose the
mainbranch
Build Configuration¶
IMPORTANT: Use these exact build settings:
| Setting | Value |
|---|---|
| Framework preset | None |
| Build command | pip install -r requirements.txt && python scripts/build_index.py && mkdocs build |
| Build output directory | site |
| Root directory | / |
| Node.js version | (leave default) |
| Environment variables | (none needed) |
Advanced Settings¶
Under Advanced: - Build timeout: 10 minutes (default is fine) - Python version: 3.8+ (usually auto-detected)
Click Save and Deploy.
Step 3: Verify Deployment¶
After the first build completes:
- Visit your Pages URL (e.g.,
https://ai-knowledge-base.pages.dev) - Verify the site loads correctly
- Check that all navigation links work
- Test the search functionality
- Verify data tables display properly
Step 4: Set Up Cloudflare Access¶
Create an Access Application¶
- In Cloudflare Dashboard, go to Zero Trust → Access → Applications
- Click Add an application
- Choose Self-hosted
- Configure the application:
Application Details:
- Application name: AI Knowledge Base
- Application domain: Your Pages URL (e.g., ai-knowledge-base.pages.dev)
- Application type: Self-hosted web application
Identity providers: - Enable the providers you want (Google, GitHub, email OTP, etc.)
Policies: Create a policy to control access:
- Policy name:
Knowledge Base Access - Action: Allow
- Rules:
- Include:
Emails→ Add your email address - Require: (optional additional requirements)
Test Access Control¶
- Open a private/incognito browser window
- Navigate to your knowledge base URL
- You should see the Cloudflare Access login page
- Log in with your configured identity provider
- Verify you can access the site after authentication
Step 5: Custom Domain (Optional)¶
To use a custom domain:
Add Custom Domain to Pages¶
- In Pages project settings, go to Custom domains
- Click Set up a custom domain
- Enter your domain (e.g.,
kb.yourdomain.com) - Follow the DNS setup instructions
Update Access Application¶
- In Access → Applications, edit your knowledge base app
- Update the Application domain to your custom domain
- Save the changes
Step 6: Automated Deployments¶
Cloudflare Pages automatically rebuilds when you push to GitHub:
# Make changes locally
python scripts/update_item.py --entity providers --id openai --set website="https://openai.com"
# Commit and push
git add .
git commit -m "Update OpenAI website URL"
git push origin main
The site will automatically rebuild and deploy within a few minutes.
Environment Variables¶
If you need environment variables (usually not required for this setup):
- Go to Pages project Settings → Environment variables
- Add variables for Production environment
- Redeploy if needed
Build Troubleshooting¶
Common Build Failures¶
Python/pip issues:
# Build command that handles Python setup better
pip install --upgrade pip && pip install -r requirements.txt && python scripts/build_index.py && mkdocs build
Schema validation failures:
- Check that all JSON files validate locally first
- Run make validate before pushing
Missing dependencies:
- Ensure requirements.txt is complete and accurate
- Test build locally: mkdocs build
Path issues: - Use relative paths in scripts - Ensure all referenced files exist in the repository
Build Logs¶
To debug build issues:
- Go to Pages project Deployments tab
- Click on the failed deployment
- View the build log output
- Look for specific error messages
Common errors:
- ModuleNotFoundError: Missing dependency in requirements.txt
- FileNotFoundError: Script can't find data files
- JSONDecodeError: Invalid JSON syntax in data files
Access Control Troubleshooting¶
Access Issues¶
If users can't access the site:
- Check Access policy: Ensure user's email is in the Allow policy
- Verify domain: Make sure Access application domain matches the site URL
- Test incognito: Try accessing in a private browser window
- Check identity provider: Ensure the user's identity provider is configured
Policy Examples¶
Team access:
Include:
- Emails ending in: @yourcompany.com
Require:
- (empty - just the email domain restriction)
Individual access:
Include:
- Emails: user1@example.com, user2@example.com, user3@example.com
Require:
- (empty - just the specific emails)
MFA required:
Monitoring and Maintenance¶
Analytics¶
Monitor your deployment:
- Pages Analytics: Traffic and performance metrics
- Access Logs: Who's accessing your knowledge base
- Build History: Deployment success/failure rates
Regular Maintenance¶
- Update dependencies: Periodically update
requirements.txt - Monitor build times: Watch for performance degradation
- Review Access logs: Ensure appropriate access patterns
- Test functionality: Regularly verify search and navigation work
Security Considerations¶
- Private repository: Keep your GitHub repository private
- Access control: Use Cloudflare Access rather than making the site public
- Audit logs: Review Access logs periodically
- Principle of least privilege: Only grant access to users who need it
- Regular reviews: Periodically review and update access policies
Cost Considerations¶
Cloudflare Pages¶
- Free tier: 500 builds/month, unlimited requests
- Paid tier: $20/month for more builds and features
Cloudflare Access¶
- Free tier: Up to 50 users
- Paid tier: $3/user/month for additional users and features
For most internal knowledge bases, the free tiers are sufficient.
For content management instructions, see Workflow Guide