Skip to content

feat: branch previews with Worker Previews - #40

Merged
tknkaa merged 10 commits into
mainfrom
feat/worker-previews
Oct 2, 2026
Merged

tknkaa merged 10 commits into
mainfrom
feat/worker-previews

Conversation

@tknkaa

@tknkaa tknkaa commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Refs #3
Supersedes #39

プレビューを、別の Worker (kanban-web-preview) から、Cloudflare の Worker Previews (2026 年 9 月公開、オープンベータ) に切り替えた。同じ Worker (kanban-web) のまま、ブランチごとに独立したプレビューができる。

できるようになったこと

  • ブランチごとに固定の URL: https://<ブランチ名>-kanban-web.ut-code.workers.dev。複数のブランチを同時に見られる
  • Durable Objects は、プレビューごとに別の名前空間が自動で作られる (バージョン URL では Durable Objects があると URL が作られなかった問題が、これにはない)
  • ログインも動く: プレビューごとに URL が違うので、wrangler preview --name … --var BETTER_AUTH_URL:<そのプレビューの URL> で渡す。アプリの認証のコードは変えていない

変更

  • wrangler.jsonc の env.preview を消し、previews ブロックを足した。D1、R2、キューは、指定しないと本番と共有されるので、プレビュー用の既存のもの (kanban-db-preview など) を指定した
  • scripts/deploy-preview.sh: ブランチ名 (WORKERS_CI_BRANCH) からプレビュー名を作り、プレビュー用の D1 にマイグレーションを適用して、wrangler preview を実行する。Workers Builds の「Non-production deploy command」に使う
  • apps/web/src/lib/preview-name.ts: ブランチ名をプレビュー名 (URL に使える形、63 文字の制限) にする純粋な関数とテスト
  • apps/web/wrangler.preview-migrations.jsonc: プレビュー用の D1 にマイグレーションを適用するためだけの設定 (d1 migrations apply は previews ブロックを読まないため)
  • ルートの package.json に "type": "module" (スクリプトを Node で直接動かすため)
  • docs/deploy.md を書き直した (いまの状態、プレビューの仕組みと制約、Workers Builds の設定値)

実際に確認したこと (ut-code のアカウント)

このブランチを、https://feat-worker-previews-kanban-web.ut-code.workers.dev にプレビューとしてデプロイして:

  • アカウント作成、タスクの作成と状態の変更、添付 (R2)、共有 (キュー)、WebSocket と Durable Objects (変更の通知が届いた)、別のオリジンの拒否 (403)
  • 本番のデータに触れていない: プレビューで作ったアカウントと添付の記録はプレビュー用の D1 にだけ、ファイルはプレビュー用の R2 にだけある

Cloudflare 側でしたこと

  • 全プレビュー共通のシークレット BETTER_AUTH_SECRET を設定した (wrangler preview base-config secret put)
  • 不要になったプレビュー用の Worker kanban-web-preview を削除した。D1、R2、キューのプレビュー用のものは、使い回すので残した

Workers Builds の設定 (ダッシュボード) で変えてほしいこと

  • Non-production deploy command: ./scripts/deploy-preview.sh
  • Build watch paths に scripts/** を足す

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://feat-worker-previews-kanban-web.ut-code.workers.dev (commit 10ceaea)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://dbfd73d1-kanban-web.ut-code.workers.dev 10ceaea 2026-10-02T13:25:10.217Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cb7dc02a-kanban-web.ut-code.workers.dev e8abbca 2026-10-02T13:23:05.411Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c8994ea9-kanban-web.ut-code.workers.dev a54c18c 2026-10-02T13:21:18.631Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cf24098e-kanban-web.ut-code.workers.dev f9eae27 2026-10-02T13:18:44.612Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f93ad00c-kanban-web.ut-code.workers.dev 1ed743b 2026-10-02T13:15:25.753Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://17418c59-kanban-web.ut-code.workers.dev edd4e05 2026-10-02T13:11:50.481Z Visit the dashboard ↗

@tknkaa
tknkaa merged commit 6f3d0e4 into main Oct 2, 2026
3 checks passed
@tknkaa
tknkaa deleted the feat/worker-previews branch October 2, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant