Skip to content

Commit 5ad622d

Browse files
authored
feat: Cloudflare deployment pipeline — wrangler.toml + GitHub Actions (#674)
Adds Cloudflare Workers deployment pipeline:\n\n- wrangler.toml with dev/production environments (non-inheritable bindings declared in both)\n- GitHub Actions workflow: push to dev → wrangler deploy, push to main → wrangler deploy --env production\n- astro.config.mjs reads SANITY_DATASET from env var (dev vs production)\n- .dev.vars.example for local development secrets\n- Replaces wrangler.jsonc with wrangler.toml\n\nD1 database IDs are placeholders — Alex creates databases and updates IDs before first successful deploy.\n\nUses pnpm workspace (pnpm/action-setup + pnpm install --frozen-lockfile)."
1 parent 2be3c58 commit 5ad622d

File tree

5 files changed

+128
-22
lines changed

5 files changed

+128
-22
lines changed

.github/workflows/deploy.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Deploy CodingCat.dev
2+
3+
on:
4+
push:
5+
branches: [dev, main]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: pnpm/action-setup@v4
15+
with:
16+
version: 9
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: "22"
21+
cache: "pnpm"
22+
23+
- name: Install dependencies
24+
run: pnpm install --frozen-lockfile
25+
26+
- name: Build (dev)
27+
if: github.ref == 'refs/heads/dev'
28+
run: pnpm --filter @codingcatdev/web build
29+
env:
30+
SANITY_PROJECT_ID: hfh83o0w
31+
SANITY_DATASET: dev
32+
33+
- name: Build (production)
34+
if: github.ref == 'refs/heads/main'
35+
run: pnpm --filter @codingcatdev/web build
36+
env:
37+
SANITY_PROJECT_ID: hfh83o0w
38+
SANITY_DATASET: production
39+
40+
- name: Deploy to dev
41+
if: github.ref == 'refs/heads/dev'
42+
run: npx wrangler deploy
43+
working-directory: apps/web
44+
env:
45+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
46+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
47+
48+
- name: Deploy to production
49+
if: github.ref == 'refs/heads/main'
50+
run: npx wrangler deploy --env production
51+
working-directory: apps/web
52+
env:
53+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
54+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

apps/web/.dev.vars.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Local development secrets — NOT committed to git
2+
# Copy to .dev.vars and fill in values
3+
4+
# better-auth
5+
BETTER_AUTH_SECRET=your-dev-secret-here
6+
BETTER_AUTH_URL=http://localhost:4321
7+
8+
# Google OAuth (for better-auth social login)
9+
GOOGLE_CLIENT_ID=your-google-client-id
10+
GOOGLE_CLIENT_SECRET=your-google-client-secret
11+
12+
# Sanity (for preview/draft mode — read queries use public API)
13+
SANITY_API_TOKEN=your-sanity-api-token
14+
SANITY_PREVIEW_SECRET=your-preview-secret

apps/web/astro.config.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import react from "@astrojs/react";
44
import sanity from "@sanity/astro";
55
import tailwindcss from "@tailwindcss/vite";
66

7+
// Sanity config — dataset comes from env var (set by wrangler vars or .env)
8+
// In astro.config.mjs, .env files are NOT loaded — use process.env
9+
const sanityProjectId = process.env.SANITY_PROJECT_ID || "hfh83o0w";
10+
const sanityDataset = process.env.SANITY_DATASET || "production";
11+
712
export default defineConfig({
813
output: "server",
914
adapter: cloudflare({
@@ -13,8 +18,8 @@ export default defineConfig({
1318
}),
1419
integrations: [
1520
sanity({
16-
projectId: "hfh83o0w",
17-
dataset: "production",
21+
projectId: sanityProjectId,
22+
dataset: sanityDataset,
1823
useCdn: false,
1924
apiVersion: "2024-01-01",
2025
}),

apps/web/wrangler.jsonc

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/web/wrangler.toml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ============================================================
2+
# CodingCat.dev — Astro on Cloudflare Workers
3+
# ============================================================
4+
# Top-level = dev environment (deployed from `dev` branch)
5+
# [env.production] = production (deployed from `main` branch)
6+
#
7+
# IMPORTANT: Bindings are NON-INHERITABLE in Cloudflare.
8+
# Every binding must be declared in BOTH top-level AND [env.production].
9+
# ============================================================
10+
11+
name = "codingcatdev"
12+
compatibility_date = "2025-03-01"
13+
compatibility_flags = ["nodejs_compat", "global_fetch_strictly_public"]
14+
15+
[observability]
16+
enabled = true
17+
18+
# --- Dev Environment (top-level = default) ---
19+
20+
[vars]
21+
ENVIRONMENT = "dev"
22+
SANITY_DATASET = "dev"
23+
SANITY_PROJECT_ID = "hfh83o0w"
24+
SITE_URL = "https://codingcatdev.workers.dev"
25+
26+
[assets]
27+
binding = "ASSETS"
28+
directory = "./dist/client"
29+
30+
[[d1_databases]]
31+
binding = "DB"
32+
database_name = "codingcat-auth-dev"
33+
database_id = "placeholder-dev-create-via-wrangler"
34+
35+
# --- Production Environment ---
36+
37+
[env.production]
38+
name = "codingcatdev-production"
39+
40+
[env.production.vars]
41+
ENVIRONMENT = "production"
42+
SANITY_DATASET = "production"
43+
SANITY_PROJECT_ID = "hfh83o0w"
44+
SITE_URL = "https://codingcat.dev"
45+
46+
[env.production.assets]
47+
binding = "ASSETS"
48+
directory = "./dist/client"
49+
50+
[[env.production.d1_databases]]
51+
binding = "DB"
52+
database_name = "codingcat-auth"
53+
database_id = "placeholder-prod-create-via-wrangler"

0 commit comments

Comments
 (0)