Automated Deployment
TIP
Prefer to do things manually, or want to understand the steps involved? Check out the manual deployment guide
TL;DR
Fork, clone, cd, install, add env vars (API key, domain and Terraform state keys), then run make deploy
Overview
You do the setup once, then make deploy runs steps 2 to 5, provisioning ~20 Cloudflare resources and deploying your application in a single command:
flowchart TB
subgraph Setup["1. Setup"]
direction LR
A[Install Tools] --> B[Fork & Clone]
B --> C[Configure .env]
end
subgraph Provision["2. Provision"]
direction LR
D[Preflight Checks] --> E[Terraform Apply]
E --> F[Generate Config]
end
subgraph Build["3. Build"]
direction LR
G[Install & Build] --> H[DB Migrations]
end
subgraph Ship["4. Deploy"]
direction LR
I[Deploy Workers] --> J[Deploy Frontend]
J --> K[Deploy Docs]
K --> L[Set Secrets]
end
subgraph Verify["5. Verify"]
direction LR
M[Smoke Tests] --> N{Success?}
N -->|Yes| O[Live!]
N -->|No| P[Check Logs]
end
Setup --> Provision --> Build --> Ship --> Verify
style O fill:#22c55e,color:#000
style P fill:#ef4444,color:#000
style D fill:#3b82f6,color:#000
style E fill:#3b82f6,color:#000Prerequisites
Install these tools before starting:
| Tool | Version | Purpose | Install |
|---|---|---|---|
| Git | Any | Clone repository | git-scm.com |
| Node.js | 22.13+, 24 or 26+ | JavaScript runtime | nodejs.org |
| pnpm | 9.5+ | Package manager | npm install -g pnpm |
| Terraform | 1.5+ | Infrastructure as code | terraform.io |
| Wrangler | Latest | Cloudflare CLI | npm install -g wrangler |
| Make | Any | Run deployment scripts | Usually pre-installed |
You'll also need:
- Cloudflare account (free tier works)
- Domain name added to Cloudflare
- GitHub account (for authentication)
- 30 minutes of time
Step 1: Fork & Clone
Fork the repository to your GitHub account, then clone it:
# Fork on GitHub first: https://github.com/lissy93/pixelflare/fork
# Clone your fork
git clone https://github.com/YOUR-USERNAME/pixelflare.git
cd pixelflare
# Install dependencies
pnpm installTIP
Forking lets you track your changes, push updates, and optionally set up CI/CD with GitHub Actions.
Step 2: Cloudflare Setup
Create API Token
- Go to Cloudflare → Profile (top-right) → API Tokens
- Click Create Token, and give it an imaginative name
- Complete the token, with the following permissions:
| Scope | Resource | Access |
|---|---|---|
| Account | AI Gateway | Edit |
| Account | Workers AI | Edit |
| Account | D1 | Edit |
| Account | Cloudflare Pages | Edit |
| Account | Workers R2 Storage | Edit |
| Account | Cloudflare Images | Edit |
| Account | Account Analytics | Read |
| Account | Workers KV Storage | Edit |
| Account | Workers Scripts | Edit |
| Account | Stream | Edit |
| Account | Access: Apps and Policies | Edit |
| Zone | Single Redirect | Edit |
| Zone | Zone WAF | Edit |
| Zone | Workers Routes | Edit |
| Zone | SSL and Certificates | Edit |
| Zone | Logs | Read |
| Zone | Page Rules | Edit |
| Zone | Firewall Services | Edit |
| Zone | DNS | Edit |
- Account Resources
- Include account: [your-account-id]
- Token is restricted to this specific Cloudflare account
- Zone Resources
- Include a specific zone
- Zone: [your-domain.com]
- Token can only operate on this DNS zone
- Client IP Address Filtering
- Not configured
- Token can be used from any IP address
- Optional restriction to specific IPs or CIDR ranges
- TTL (Time To Live)
- Not set
- Token does not expire automatically
- Optional start and end dates can limit token lifetime
By the end, your screen should look similar to this:
Get Account ID
- Go to Cloudflare Dashboard
- Click any domain
- Scroll down in the right sidebar - copy your Account ID
Example Account ID location
Step 3: Configure Environment
Create your environment file:
cp .env.example .envEdit .env and set these three required variables:
# Essential Configuration
CLOUDFLARE_ACCOUNT_ID='abc123def456...' # From step 2
CLOUDFLARE_API_TOKEN='your-api-token' # From step 2
DOMAIN='yourdomain.com' # Your domain (needs to be Cloudflare)Everything else has sensible defaults or is generated for you.
NOTE
Optional: Set ACCESS_TEAM_DOMAIN='your-team-name' to customize your Cloudflare Access subdomain (e.g., your-team.cloudflareaccess.com).
Terraform State
Terraform keeps a record of everything it creates, along with the secrets it generates, in a state file. Pixelflare stores it in a private R2 bucket, so it's never lost, and deploys from your machine and from GitHub Actions stay in sync.
Create the bucket:
npx wrangler r2 bucket create pixflare-terraform-stateThen in the Cloudflare dashboard, go to R2 Object Storage → Manage API Tokens, and create an Account API token with Object Read & Write, limited to just that bucket. Add its keys to .env:
AWS_ACCESS_KEY_ID='<r2 access key id>'
AWS_SECRET_ACCESS_KEY='<r2 secret access key>'
AWS_ENDPOINT_URL_S3='https://<account-id>.r2.cloudflarestorage.com'They have AWS names because that's what Terraform's S3 backend reads, but nothing talks to AWS.
WARNING
Keep this bucket private, and don't delete it. Without the state, Terraform would generate new secrets, including your encryption key, and try to recreate your live resources.
Optional Configuration
See the configuration guides for details on configuring other features.
Step 4: Deploy
Run the deployment script:
make deployThis will:
- ✓ Preflight checks - Verify tools, credentials, domain
- ✓ Terraform apply - Create all Cloudflare resources
- ✓ Generate configs - Create wrangler.toml from Terraform outputs
- ✓ Install & build - Compile TypeScript, bundle assets
- ✓ Database migrations - Set up D1 schema
- ✓ Deploy Workers - Upload API and gateway workers
- ✓ Deploy frontend - Build and deploy SvelteKit app to Pages
- ✓ Set secrets - Upload API keys and generated secrets
- ✓ Smoke tests - Verify deployment is working
Deployment typically takes 5-10 minutes on first run.
IMPORTANT
Secrets are auto-generated by Terraform if not provided. You don't need to manually create API_HASH_SECRET, UPLOAD_TOKEN_SECRET, etc. - they're generated securely and set automatically.
What Gets Created
Your deployment provisions:
Storage:
- R2 bucket (
pixflare-production-images) - D1 database (
pixflare-production-db) - KV namespace (
pixflare-production-cache) - 4 Queues (variants, backups, custom domains, webhooks)
Workers:
- API Worker (Hono-based REST API)
- Gateway Worker (optional, single-domain routing)
Frontend:
- Cloudflare Pages project
- Custom domain DNS records
Authentication:
- Cloudflare Access application (optional)
- GitHub OAuth identity provider
Optional:
- Vectorize index (AI embeddings)
- Analytics Engine dataset
- WAF rules (R2 protection)
Step 5: Verify
Once deployment completes, some smoke tests will run and check that everything is up and running like it should.
You can also test this yourself, for example:
- Frontend:
https://yourdomain.com - API Health:
https://yourdomain.com/api/health - API Docs:
https://yourdomain.com/api/v1/docs
You should now be able to login and get started!
- Visit your frontend URL
- Click Sign In
- Authenticate with GitHub via Cloudflare Access
- Start uploading cat pics!
Troubleshooting
Having issues? See the Troubleshooting Guide for common problems and solutions.
Quick checks:
- Verify
.envhas correctCLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID, andDOMAIN - Ensure API token has all required permissions
- Check domain is active in Cloudflare
- Run
make helpto see all available commands
Deployment Options
make deploy runs every step. To skip some, or deploy just one part, run the script behind it with any of these options:
./scripts/deploy.sh production --workers-only| Option | What it does |
|---|---|
--skip-terraform | Skips Terraform, for when your infrastructure hasn't changed |
--skip-tests | Skips the test suite |
--skip-build | Skips building the packages |
--skip-migrations | Skips the D1 database migrations |
--skip-secrets | Skips setting the Worker secrets |
--skip-smoke-tests | Skips the checks at the end |
--workers-only | Deploys the Workers, but not the frontend or docs |
--frontend-only | Deploys the frontend and docs, but not the Workers |
--dry-run | Lists the steps it would run, without running them |
Each step is also its own make target, like make terraform-apply or make deploy-workers, which is handy for re-running the one that failed. Run make help to see them all.
Updating Pixelflare
To update your deployment, re-pull the latest code, update dependencies, and re-deploy. Or:
make update
make deployTerraform will only update changed resources.
Next Steps
Your Pixelflare instance is live! But there's more features you can enable and configure, with simple toggles and env vars. Explore these in the Config docs 😃