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. |
Environment Variables
Section titled “Environment Variables”| Name | Required | Description |
|---|---|---|
CLOUDFLARE_API_TOKEN |
Yes | Cloudflare API token with permission to deploy (Account → Cloudflare Pages → Edit, or the equivalent Workers 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).