Deployment Guide
This guide walks you through setting up automated deployment for your documentation site using GitLab CI/CD and Cloudflare Pages.
Prerequisites
Section titled “Prerequisites”- A GitLab repository with this template
- A Cloudflare account
- Admin access to your GitLab project settings
Step 1: Cloudflare Setup
Section titled “Step 1: Cloudflare Setup”1.1 Create a Pages Project
Section titled “1.1 Create a Pages Project”- Log into Cloudflare Dashboard
- Navigate to Pages in the left sidebar
- Click Create a project
- Select Upload assets (not Connect to Git)
- This creates an empty project that we’ll deploy to via CI/CD
- You don’t need to upload any files at this step
- Enter a project name that matches what you’ll use for
CLOUDFLARE_PAGES_PROJECT- Use a descriptive name like
my-docsorproject-documentation - Remember this exact name - it must match your environment variable
- Use a descriptive name like
- Click Create project - after this the page is created. No need to upload anything. You can leave the page
- Note your Account ID from the dashboard URL or sidebar
- It looks like:
https://dash.cloudflare.com/[ACCOUNT_ID]/pages - You’ll need this for the
CLOUDFLARE_ACCOUNT_IDvariable
- It looks like:
1.2 Generate API Token
Section titled “1.2 Generate API Token”- Go to Cloudflare API Tokens
- Click Create Token
- Use the Custom token template
- Configure permissions:
- Zone:Zone:Read (if using custom domains)
- Zone:Page Rules:Edit (if using custom domains)
- Account:Cloudflare Pages:Edit
- Acount:Worker:Edit (add everything related to workers)
- Copy the generated token
Step 2: GitLab Configuration
Section titled “Step 2: GitLab Configuration”2.1 Set Environment Variables
Section titled “2.1 Set Environment Variables”Go to your GitLab project: Settings > CI/CD > Variables
Add these variables (mark as Protected and Masked where appropriate):
| Variable | Value | Type | Protected | Masked |
|---|---|---|---|---|
CLOUDFLARE_PAGES_PROJECT | Your Pages project name | Variable | ✅ | ❌ |
CLOUDFLARE_API_TOKEN | Your API token | Variable | ✅ | ✅ |
CLOUDFLARE_ACCOUNT_ID | Your account ID | Variable | ✅ | ✅ |
WEBSITE_PASSWORD | Your site password (optional) | Variable | ✅ | ✅ |
2.2 Verify CI/CD Configuration
Section titled “2.2 Verify CI/CD Configuration”The .gitlab-ci.yml file should already be configured. It includes:
- Build Stage: Installs dependencies and builds the site
- Deploy Stage: Deploys to Cloudflare Pages using Wrangler
Step 3: Deploy
Section titled “Step 3: Deploy”- Commit and Push: Any push to your repository will trigger deployment
- Monitor Progress: Check the CI/CD pipeline in GitLab
- Access Your Site: Visit
https://your-project-name.pages.dev
Password Protection
Section titled “Password Protection”If you set the WEBSITE_PASSWORD variable, your site will be protected with a login page.
How It Works
Section titled “How It Works”- Users see a login page before accessing content
- Correct password sets a secure cookie valid for 1 day
- Authentication is handled by Cloudflare Functions
Important Notes
Section titled “Important Notes”- Password Changes: Require redeployment to take effect
- Security: Passwords are hashed using SHA-256
- Sessions: Login persists across browser sessions
Changing the Password
Section titled “Changing the Password”- Update the
WEBSITE_PASSWORDvariable in GitLab - Trigger a new deployment (push a commit or manual pipeline)
- The new password will be active after deployment completes
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Build Failures
Section titled “Build Failures”Error: Failed to install dependenciesSolution: Check that pnpm-lock.yaml is committed to the repository.
Deployment Failures
Section titled “Deployment Failures”Error: Authentication failedSolutions:
- Verify
CLOUDFLARE_API_TOKENhas correct permissions - Ensure
CLOUDFLARE_ACCOUNT_IDis correct - Check that the Pages project exists
Password Not Working
Section titled “Password Not Working”Solution: Redeploy the project after changing WEBSITE_PASSWORD.
Page Not Found (404)
Section titled “Page Not Found (404)”Solutions:
- Verify
CLOUDFLARE_PAGES_PROJECTmatches your actual project name - Check that the deployment completed successfully
- Wait a few minutes for DNS propagation
Checking Deployment Status
Section titled “Checking Deployment Status”- GitLab: Go to CI/CD > Pipelines to see build status
- Cloudflare: Check Pages dashboard for deployment history
- Logs: View detailed logs in both GitLab and Cloudflare
Advanced Configuration
Section titled “Advanced Configuration”Custom Domains
Section titled “Custom Domains”- Add your domain in Cloudflare Pages settings
- Update DNS records as instructed
- Modify environment variables if needed
Branch Deployments
Section titled “Branch Deployments”The CI/CD is configured to deploy all branches, creating preview URLs for each branch automatically.