Cloudflare
Deploys a release artifact to Cloudflare, either as a Cloudflare Worker (optionally with static assets) or as a Cloudflare Pages site.
The target extracts a ZIP artifact and shells out to the wrangler CLI to perform the deployment. wrangler is bundled in the Craft Docker image.
Configuration
Section titled “Configuration”| Option | Description |
|---|---|
deployType |
worker (default) or pages. |
projectName |
Cloudflare Pages project name. Required when deployType is pages. |
productionBranch |
The Pages project’s production branch name. Optional — when omitted, Craft reads it from the Cloudflare API so the release lands on production. See Production deployments. Only used for deployType: pages. |
wranglerCliPath |
Path to the wrangler binary. Default: wrangler (or the WRANGLER_BIN env var). |
workingDir |
Subdirectory within the extracted artifact to deploy from. For worker deploys this is where the wrangler.toml lives. |
API token permissions
Section titled “API token permissions”Set CLOUDFLARE_API_TOKEN to an API token scoped to the Cloudflare account
that owns the deployment. Grant only the account permission required by the
configured deploy type:
deployType |
Minimum API token permission |
|---|---|
worker |
Account → Workers Scripts → Edit |
pages |
Account → Cloudflare Pages → Edit |
If one token is used for both deploy types, grant both permissions. Do not add
user, zone, billing, account-settings, or read permissions: this target does
not require them. The account ID is an identifier, not a permission; use the
optional CLOUDFLARE_ACCOUNT_ID value when the token can access multiple
accounts.
See Cloudflare’s API token permissions reference for the current permission names and descriptions.
Environment Variables
Section titled “Environment Variables”| Name | Required | Description |
|---|---|---|
CLOUDFLARE_API_TOKEN |
Yes | Cloudflare API token with the minimum permission described in API token permissions. Passed to wrangler via the environment, never on the command line. |
CLOUDFLARE_ACCOUNT_ID |
No | Cloudflare account ID. This is an identifier, not a secret. When unset, wrangler auto-discovers it for single-account tokens; set it explicitly if your token can access multiple accounts. |
Production deployments (Pages)
Section titled “Production deployments (Pages)”wrangler pages deploy --branch <X> deploys to production only when <X> exactly matches the project’s server-side production branch; any other value silently produces a preview deployment (this is not an error). To make releases reliably land on production, Craft resolves the production branch as follows:
- If
productionBranchis set in the config, it is used verbatim. - Otherwise, if the account ID is known, Craft reads the project’s production branch from the Cloudflare API (
GET /accounts/{id}/pages/projects/{name}) — the same callwranglermakes internally, so it needs no token scope beyond deploying. - If neither is available, Craft omits
--branch; a bare deploy from Craft’s temporary (non-git) directory defaults to production.
Default Behavior
Section titled “Default Behavior”By default, this target:
- Looks for a single artifact matching
cloudflare.zip(or*-cloudflare.zip). Override withincludeNames. - Extracts its contents (flattening a single top-level directory if present).
- Deploys via
wrangler.
Example
Section titled “Example”Cloudflare Worker (with a wrangler.toml in the artifact):
targets: - name: cloudflare deployType: worker workingDir: workerCloudflare Pages (static site):
targets: - name: cloudflare deployType: pages projectName: my-docs-site # productionBranch is optional; inferred from the API when omitted.Workflow
Section titled “Workflow”- Create a
cloudflare.zipartifact in your CI workflow (e.g. your Worker pluswrangler.toml, or the built static site for Pages). - Configure the target in
.craft.yml. - Set
CLOUDFLARE_API_TOKENin your environment (andCLOUDFLARE_ACCOUNT_IDif your token can access multiple accounts).