Deployment
PageZERO is built specifically for Cloudflare’s infrastructure, leveraging Cloudflare Workers for compute and Cloudflare D1 for database storage.
The deployment process involves setting up D1 databases and deploying your application as Cloudflare Workers. You can deploy manually or set up automated deployments through a GitHub Actions CI/CD pipeline.
Cloudflare setup
Section titled “Cloudflare setup”-
If you don’t have a Cloudflare account, create one at https://dash.cloudflare.com/sign-up.
-
Go to your project root directory
-
Login to Cloudflare through
wranglerCLI:Terminal window bunx wrangler login -
Create production and preview database:
Terminal window bunx wrangler d1 create <project-name>-productionbunx wrangler d1 create <project-name>-preview -
Update
wrangler.jsonwith the returned project name, database names, anddatabase_ids -
Create Cloudflare Workers through initial deployment:
Terminal window bun run deploy:productionbun run deploy:preview -
Add the necessary secrets for your Cloudflare Workers:
No secrets are needed for the open-source edition.
The following secrets are needed to successfully setup authentication, email delivery and payments services:
Terminal window bunx wrangler secret put OTP_SECRET --env=productionbunx wrangler secret put OTP_SECRET --env=previewbunx wrangler secret put SESSION_COOKIE_SECRET --env=productionbunx wrangler secret put SESSION_COOKIE_SECRET --env=previewbunx wrangler secret put RESEND_API_KEY --env=productionbunx wrangler secret put RESEND_API_KEY --env=previewbunx wrangler secret put POLAR_WEBHOOK_SECRET --env=productionbunx wrangler secret put POLAR_WEBHOOK_SECRET --env=previewbunx wrangler secret put CLOUDFLARE_TURNSTILE_SECRET_KEY --env=productionbunx wrangler secret put CLOUDFLARE_TURNSTILE_SECRET_KEY --env=previewAdditionally, set
Get PowerUP Learn moreCLOUDFLARE_TURNSTILE_PUBLIC_KEYinwrangler.jsonunderenv.production.varsandenv.preview.vars.
Manual
Section titled “Manual”-
Perform initial Cloudflare setup first to create D1 databases and Cloudflare Workers.
-
Set the following environment variables in your project’s
.envfile:Terminal window CLOUDFLARE_ACCOUNT_ID=<your-cloudflare-account-id>CLOUDFLARE_API_TOKEN=<your-cloudflare-api-token> -
Perform Cloudflare D1 databases migrations:
Terminal window bun run db:migrate:previewbun run db:migrate:production -
Perform Cloudflare Workers deployments:
Terminal window bun run deploy:previewbun run deploy:production
Automatic
Section titled “Automatic”Automatic deployment happens through the GitHub Actions CI/CD pipeline. Once the pipeline is set up,
every merge to the main branch will automatically trigger deployment to Cloudflare Workers and a database
migration for Cloudflare D1. Additionally, every PR will trigger a preview deployment, allowing you to access a
specific version of your app for each PR.
-
Perform initial Cloudflare setup first to create D1 databases and Cloudflare Workers.
-
Login through
gh auth login -
Create a GitHub repo for the project and push all changes
Terminal window gh repo create <project-name> --private --source=. --remote=origin --push -
Add the following repository variables:
Terminal window gh variable set CLOUDFLARE_ACCOUNT_ID --body "<your-cloudflare-account-id>" -
Add the following repository secret:
Terminal window gh secret set CLOUDFLARE_API_TOKENgh secret set CLOUDFLARE_API_TOKEN --app dependabot
Now you can test everything. Create a PR in your project’s GitHub repository. You should see an action in the “Actions” section being triggered. If the basic checks pass, the workflow will perform a preview deployment to Cloudflare Workers and run a database migration on your preview database. After deployment, a “View deployment” button should appear in your PR with a link to the preview deployment.
When you merge the PR to main, a production deployment will occur, and a database migration will be performed on your production database.