Deploy Commands
CruzJS deployment commands manage the full lifecycle of your Cloudflare environments: initialization, deployment, status checking, and teardown. The deployment pipeline handles building, running migrations, deploying the Pages application, and deploying all standalone workers automatically.
cruz init
Section titled “cruz init”Initializes a new Cloudflare environment by creating the required infrastructure resources (D1 database, KV namespace, R2 bucket).
# Initialize a production environmentcruz init production
# Initialize stagingcruz init staging
# Auto-confirm all promptscruz init production --yesWhat It Creates
Section titled “What It Creates”cruz init reads your cruz.config.ts to determine which resources your application needs, then creates them on Cloudflare:
| Resource | Created When |
|---|---|
| D1 Database | Always (required for Drizzle ORM) |
| KV Namespace | When bindings.kv is enabled in config |
| R2 Bucket | When bindings.r2 is enabled in config |
After creation, the resource IDs are stored in .cruz.json so subsequent commands can reference them.
Options
Section titled “Options”| Flag | Description |
|---|---|
--yes, -y | Skip confirmation prompts |
--account-id <id> | Specify Cloudflare account ID (otherwise auto-detected) |
Authentication
Section titled “Authentication”Before running cruz init, you must authenticate with Cloudflare. Either:
- Run
wrangler loginto authenticate via the browser, or - Set the
CLOUDFLARE_API_TOKENenvironment variable with an API token from the Cloudflare Dashboard.
cruz deploy
Section titled “cruz deploy”Runs the full deployment pipeline: generate wrangler.toml, build the application, apply D1 migrations, deploy to Cloudflare Pages, and deploy all standalone workers.
# Deploy to productioncruz deploy production
# Deploy to stagingcruz deploy staging
# Auto-confirm without promptingcruz deploy production --yesDeployment Pipeline
Section titled “Deployment Pipeline”The cruz deploy command executes these steps in order:
- Generate wrangler.toml — Creates the Wrangler configuration from
cruz.config.tsand the target environment’s resource IDs. - Build application — Runs
npx react-router buildto compile the React application. - Bundle Pages worker — Bundles the server-side worker for Cloudflare Pages.
- Apply D1 migrations — Runs pending migrations against the remote D1 database.
- Deploy to Pages — Uploads static assets and the worker to Cloudflare Pages.
- Deploy standalone workers — Discovers and deploys all workers in
external-processes/. - Verify deployment — Runs a health check against the deployed URL.
Options
Section titled “Options”| Flag | Description |
|---|---|
--skip-build | Skip steps 2 and 3 (use existing build output) |
--skip-migrate | Skip step 4 (do not run migrations) |
--yes, -y | Skip the confirmation prompt |
Example Output
Section titled “Example Output” Cruz Deploy production
✓ Generate wrangler.toml wrangler.toml generated ✓ Build application Built successfully ✓ Bundle Pages worker Worker bundled ✓ Apply D1 migrations Migrations applied ✓ Deploy to Pages Deployed successfully ✓ Deploy worker: email-sender Deployed successfully ✓ Verify deployment Health check passed (200)
✓ Deployed to Cloudflare! URL: https://my-app.pages.devcruz deploy preview
Section titled “cruz deploy preview”Creates a preview deployment from the current git branch. Preview deployments are isolated environments with their own URL, database, and KV namespace.
# Deploy a preview from the current branchcruz deploy previewHow Preview Deploys Work
Section titled “How Preview Deploys Work”- The CLI reads the current git branch name (e.g.,
feature/new-dashboard). - It sanitizes the branch name for use as a Cloudflare resource name (e.g.,
feature-new-dashboard). - If no environment exists for this branch, it auto-initializes one by creating a D1 database and KV namespace.
- The application is deployed to a branch-specific URL.
The preview URL follows the pattern:
https://<branch-name>.<project-name>.pages.devRestrictions
Section titled “Restrictions”- You cannot deploy a preview from the
mainormasterbranch. Usecruz deploy productioninstead. - Preview environments are auto-created but not auto-destroyed. Use
cruz destroyto clean them up.
cruz status
Section titled “cruz status”Shows the current state of all configured Cloudflare environments, including resource IDs, custom domains, and last deployment timestamps.
# Show all environmentscruz status
# Show a specific environmentcruz status --env productionExample Output
Section titled “Example Output” Cruz Status
Environment: production Account: abc123 D1: my-app-production-db (id: d1_xyz) KV: my-app-production-cache (id: kv_xyz) Domain: app.example.com Deployed: 2025-03-10T14:32:00Z
Environment: staging Account: abc123 D1: my-app-staging-db (id: d1_abc) KV: my-app-staging-cache (id: kv_abc) Deployed: 2025-03-09T10:15:00Zcruz destroy
Section titled “cruz destroy”Tears down a Cloudflare environment and its associated resources. This is a destructive operation that deletes the D1 database, KV namespace, and R2 bucket for the target environment.
# Destroy a staging environmentcruz destroy staging
# Auto-confirmcruz destroy staging --yes
# Destroying production requires --forcecruz destroy production --force --yesSafety Guards
Section titled “Safety Guards”- Destroying a production environment requires the
--forceflag. Without it, the command refuses to run. - The command prompts for confirmation unless
--yesis passed. - Resource deletion is permanent. Database data cannot be recovered.
Options
Section titled “Options”| Flag | Description |
|---|---|
--yes, -y | Skip the confirmation prompt |
--force | Allow destroying production environments |
Environment Management
Section titled “Environment Management”Environment Lifecycle
Section titled “Environment Lifecycle”# 1. Initialize the environment (creates D1, KV, R2)cruz init staging
# 2. Deploy to itcruz deploy staging
# 3. Check its statuscruz status --env staging
# 4. Tear it down when no longer neededcruz destroy staging --yesProduction vs Preview
Section titled “Production vs Preview”| Aspect | Production | Preview |
|---|---|---|
| Init | cruz init production (manual) | Auto-initialized on first deploy preview |
| Deploy | cruz deploy production | cruz deploy preview |
| URL | <project>.pages.dev or custom domain | <branch>.<project>.pages.dev |
| Destroy | Requires --force | Standard cruz destroy preview-<branch> |
| Migrations | Always applied | Applied to isolated D1 database |
CI/CD Integration
Section titled “CI/CD Integration”For automated deployments, use the --yes flag to skip confirmation prompts:
# In a CI pipelinecruz deploy production --yes
# Or with skip flags for faster deploys when appropriatecruz deploy production --yes --skip-build # If build was done in a previous stepSet the CLOUDFLARE_API_TOKEN environment variable in your CI environment instead of using wrangler login.