feat(self-host): Tier 1 Docker / Node self-hosted deployment#990
Merged
Conversation
7491dc5 to
f43cb13
Compare
Adds a self-hosting adapter layer so SonicJS runs outside Cloudflare Workers with no code changes to the core CMS. - **sqlite-driver.ts** — D1Database-compatible SQLite driver via better-sqlite3; auto-migrates fresh databases; handles tsup's flat-dist layout by walking up directories to find migrations/ - **filesystem-driver.ts** — R2Bucket-compatible local storage adapter - **memory-kv-driver.ts** — KVNamespace adapter with optional JSON persistence across restarts - **sync-queue-driver.ts** — MessageQueue adapter (synchronous, in-process) - **node-server.ts** — wraps a SonicJS Hono app in a fresh Hono wrapper so DB/storage/KV bindings are injected BEFORE bootstrap middleware runs (ordering fix: Hono appends middleware in registration order) - **my-sonicjs-app/src/self-host.ts** — Node/Bun entry point; reads env vars (SONICJS_DB_PATH, SONICJS_STORAGE_PATH, etc.) and serves via @hono/node-server - **Dockerfile** — multi-stage build (builder compiles native modules; runtime Alpine copies node_modules + built dist) - **docker-compose.yml** — persistent volume for /app/data - Added missing `password_reset_token`, `password_reset_expires`, and `two_factor_enabled` columns to auth_user (were in schema.ts / Drizzle model but missing from 0001_core.sql migration) - Unit tests for all four adapters (sqlite-driver, filesystem, kv, queue) using the real better-sqlite3 harness per R10 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Creates initial admin user (admin@sonicjs.com / sonicjs!) on first boot using @better-auth/utils/password for hash compatibility. Idempotent — skips silently if any user already exists. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Admin route is gated by requireRbac('portal','access') — seeding
auth_user alone isn't enough. Call bootstrapDocumentTypes +
ensureSystemRbacSeed + addUserRoleByName via the D1-compatible
SqliteDriver after creating the auth_user/auth_account rows.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rebase onto origin/main (resolved migrations-bundle conflict by regenerating from our updated 0001_core.sql) - Move better-sqlite3 to root optionalDependencies so npm ci in CI can install the native module for sqlite-driver tests - Inject better-sqlite3 lock file entry (npm skips it locally because the package is already resolved via parent node_modules in the conductor worktree — CI needs an explicit entry) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
f43cb13 to
eae8588
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
better-sqlite3; auto-migrates fresh databases; walk-up directory resolution for migration files (tsup flat-dist safe)my-sonicjs-app/src/self-host.ts— Node/Bun entry point; readsSONICJS_DB_PATH,SONICJS_STORAGE_PATH,SONICJS_KV_PATH,PORT/app/datavolumepassword_reset_token,password_reset_expires,two_factor_enabledtoauth_userin0001_core.sql(present in Drizzle schema but missing from migration)Smoke test results (local Docker)
Test plan
packages/coreunit tests for all four adapters (sqlite-driver,filesystem-driver,memory-kv-driver,sync-queue-driver)Related
Closes #939 (non-Cloudflare hosting issue)
🤖 Generated with Claude Code