All skills
davila7 avatar

/cloudflare-deploy

@72b6736

Deploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.

Use this Skill: https://skilld.dev/gh/davila7/claude-code-templates/cloudflare-deploy

This session only. Nothing lands on disk.

referencespulumiconfiguration.md

≈1.4k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Resource Configuration

Workers (cloudflare.WorkerScript)

import * as cloudflare from "@pulumi/cloudflare";
import * as fs from "fs";

const worker = new cloudflare.WorkerScript("my-worker", {
    accountId: accountId,
    name: "my-worker",
    content: fs.readFileSync("./dist/worker.js", "utf8"),
    module: true, // ES modules
    compatibilityDate: "2025-01-01",
    compatibilityFlags: ["nodejs_compat"],
    
    // v6.x: Observability
    logpush: true, // Enable Workers Logpush
    tailConsumers: [{service: "log-consumer"}], // Stream logs to Worker
    
    // v6.x: Placement
    placement: {mode: "smart"}, // Smart placement for latency optimization
    
    // Bindings
    kvNamespaceBindings: [{name: "MY_KV", namespaceId: kv.id}],
    r2BucketBindings: [{name: "MY_BUCKET", bucketName: bucket.name}],
    d1DatabaseBindings: [{name: "DB", databaseId: db.id}],
    queueBindings: [{name: "MY_QUEUE", queue: queue.id}],
    serviceBindings: [{name: "OTHER_SERVICE", service: other.name}],
    plainTextBindings: [{name: "ENV_VAR", text: "value"}],
    secretTextBindings: [{name: "API_KEY", text: secret}],
    
    // v6.x: Advanced bindings
    analyticsEngineBindings: [{name: "ANALYTICS", dataset: "my-dataset"}],
    browserBinding: {name: "BROWSER"}, // Browser Rendering
    aiBinding: {name: "AI"}, // Workers AI
    hyperdriveBindings: [{name: "HYPERDRIVE", id: hyperdriveConfig.id}],
});

Workers KV (cloudflare.WorkersKvNamespace)

const kv = new cloudflare.WorkersKvNamespace("my-kv", {
    accountId: accountId,
    title: "my-kv-namespace",
});

// Write values
const kvValue = new cloudflare.WorkersKvValue("config", {
    accountId: accountId,
    namespaceId: kv.id,
    key: "config",
    value: JSON.stringify({foo: "bar"}),
});

R2 Buckets (cloudflare.R2Bucket)

const bucket = new cloudflare.R2Bucket("my-bucket", {
    accountId: accountId,
    name: "my-bucket",
    location: "auto", // or "wnam", etc.
});

D1 Databases (cloudflare.D1Database)

const db = new cloudflare.D1Database("my-db", {accountId, name: "my-database"});

// Migrations via wrangler
import * as command from "@pulumi/command";
const migration = new command.local.Command("d1-migration", {
    create: pulumi.interpolate`wrangler d1 execute ${db.name} --file ./schema.sql`,
}, {dependsOn: [db]});

Queues (cloudflare.Queue)

const queue = new cloudflare.Queue("my-queue", {accountId, name: "my-queue"});

// Producer
const producer = new cloudflare.WorkerScript("producer", {
    accountId, name: "producer", content: code,
    queueBindings: [{name: "MY_QUEUE", queue: queue.id}],
});

// Consumer
const consumer = new cloudflare.WorkerScript("consumer", {
    accountId, name: "consumer", content: code,
    queueConsumers: [{queue: queue.name, maxBatchSize: 10, maxRetries: 3}],
});

Pages Projects (cloudflare.PagesProject)

const pages = new cloudflare.PagesProject("my-site", {
    accountId, name: "my-site", productionBranch: "main",
    buildConfig: {buildCommand: "npm run build", destinationDir: "dist"},
    source: {
        type: "github",
        config: {owner: "my-org", repoName: "my-repo", productionBranch: "main"},
    },
    deploymentConfigs: {
        production: {
            environmentVariables: {NODE_VERSION: "18"},
            kvNamespaces: {MY_KV: kv.id},
            d1Databases: {DB: db.id},
        },
    },
});

DNS Records (cloudflare.DnsRecord)

const zone = cloudflare.getZone({name: "example.com"});
const record = new cloudflare.DnsRecord("www", {
    zoneId: zone.then(z => z.id), name: "www", type: "A",
    content: "192.0.2.1", ttl: 3600, proxied: true,
});

Workers Domains/Routes

// Route (pattern-based)
const route = new cloudflare.WorkerRoute("my-route", {
    zoneId: zoneId,
    pattern: "example.com/api/*",
    scriptName: worker.name,
});

// Domain (dedicated subdomain)
const domain = new cloudflare.WorkersDomain("my-domain", {
    accountId: accountId,
    hostname: "api.example.com",
    service: worker.name,
    zoneId: zoneId,
});

Assets Configuration (v6.x)

Serve static assets from Workers:

const worker = new cloudflare.WorkerScript("app", {
    accountId: accountId,
    name: "my-app",
    content: code,
    assets: {
        path: "./public", // Local directory
        // Assets uploaded and served from Workers
    },
});

v6.x Versioned Deployments (Advanced)

For gradual rollouts, use 3-resource pattern:

// 1. Worker (container for versions)
const worker = new cloudflare.Worker("api", {
    accountId: accountId,
    name: "api-worker",
});

// 2. Version (immutable code + config)
const version = new cloudflare.WorkerVersion("v1", {
    accountId: accountId,
    workerId: worker.id,
    content: fs.readFileSync("./dist/worker.js", "utf8"),
    compatibilityDate: "2025-01-01",
    compatibilityFlags: ["nodejs_compat"],
    // Note: Bindings configured at deployment level
});

// 3. Deployment (version + bindings + traffic split)
const deployment = new cloudflare.WorkersDeployment("prod", {
    accountId: accountId,
    workerId: worker.id,
    versionId: version.id,
    // Bindings applied to deployment
    kvNamespaceBindings: [{name: "MY_KV", namespaceId: kv.id}],
});

When to use: Blue-green deployments, canary releases, gradual rollouts
When NOT to use: Simple single-version deployments (use WorkerScript)


See: README.md, api.md, patterns.md, gotchas.md

Source: SKILL.md on GitHub

2 warnings1d4 checks · Risk SAFE
  • Gen Agent Trust Hub1d

    The skill is a comprehensive documentation and reference suite for deploying applications and infrastructure to the Cloudflare platform. It provides detailed technical guidance, code snippets, and architectural patterns for various services including Workers, Pages, D1, R2, and AI Gateway. No malicious patterns, obfuscation, or unauthorized data access were detected.

  • Socket1d

    1 alert: gptAnomaly

  • Snyk1d

    Risk: LOW · No issues

  • Runlayer7mo

    304/310 files flagged

Signed by skilld at 72b6736. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 19 hours ago.

Activeupdated 8 months ago
author
openai

README badge

README badge for davila7/claude-code-templates/cloudflare-deploy