mirror of
https://github.com/different-ai/openwork
synced 2026-04-25 17:15:34 +02:00
5.2 KiB
5.2 KiB
Den Service
Control plane for hosted workers. Provides Better Auth, worker CRUD, and provisioning hooks.
Quick start
pnpm install
cp .env.example .env
pnpm dev
Environment
DATABASE_URLMySQL connection URLBETTER_AUTH_SECRET32+ char secretBETTER_AUTH_URLbase URL for auth callbacksGITHUB_CLIENT_IDoptional OAuth app client ID for GitHub sign-inGITHUB_CLIENT_SECREToptional OAuth app client secret for GitHub sign-inPORTserver portCORS_ORIGINScomma-separated list of trusted browser origins (used for Better Auth origin validation + Express CORS)PROVISIONER_MODEstuborrenderWORKER_URL_TEMPLATEtemplate string with{workerId}RENDER_API_BASERender API base URL (defaulthttps://api.render.com/v1)RENDER_API_KEYRender API key (required forPROVISIONER_MODE=render)RENDER_OWNER_IDRender workspace owner id (required forPROVISIONER_MODE=render)RENDER_WORKER_REPOrepository URL used to create worker servicesRENDER_WORKER_BRANCHbranch used for worker servicesRENDER_WORKER_ROOT_DIRrenderrootDirfor worker servicesRENDER_WORKER_PLANRender plan for worker servicesRENDER_WORKER_REGIONRender region for worker servicesRENDER_WORKER_OPENWORK_VERSIONopenwork-orchestratornpm version installed in workersRENDER_WORKER_NAME_PREFIXservice name prefixRENDER_WORKER_PUBLIC_DOMAIN_SUFFIXoptional domain suffix for worker custom URLs (e.g.openwork.studio-><worker-id>.openwork.studio)RENDER_CUSTOM_DOMAIN_READY_TIMEOUT_MSmax time to wait for vanity URL health before falling back to Render URLRENDER_PROVISION_TIMEOUT_MSmax time to wait for deploy to become liveRENDER_HEALTHCHECK_TIMEOUT_MSmax time to wait for worker health checksRENDER_POLL_INTERVAL_MSpolling interval for deploy + health checksVERCEL_API_BASEVercel API base URL (defaulthttps://api.vercel.com)VERCEL_TOKENVercel API token used to upsert worker DNS recordsVERCEL_TEAM_IDoptional Vercel team id for scoped API callsVERCEL_TEAM_SLUGoptional Vercel team slug for scoped API calls (used whenVERCEL_TEAM_IDis unset)VERCEL_DNS_DOMAINVercel-managed DNS zone used for worker records (defaultopenwork.studio)POLAR_FEATURE_GATE_ENABLEDenable cloud-worker paywall (trueorfalse)POLAR_API_BASEPolar API base URL (defaulthttps://api.polar.sh)POLAR_ACCESS_TOKENPolar organization access token (required when paywall enabled)POLAR_PRODUCT_IDPolar product ID used for checkout sessions (required when paywall enabled)POLAR_BENEFIT_IDPolar benefit ID required to unlock cloud workers (required when paywall enabled)POLAR_SUCCESS_URLredirect URL after successful checkout (required when paywall enabled)POLAR_RETURN_URLreturn URL shown in checkout (required when paywall enabled)
Auth setup (Better Auth)
Generate Better Auth schema (Drizzle):
npx @better-auth/cli@latest generate --config src/auth.ts --output src/db/better-auth.schema.ts --yes
Apply migrations:
pnpm db:generate
pnpm db:migrate
API
GET /healthGET /demo web app (sign-up + auth + worker launch)GET /v1/meGET /v1/workers(list recent workers for signed-in user/org)POST /v1/workers- Cloud launches return
202quickly with workerstatus=provisioningand continue provisioning asynchronously. - Returns
402 payment_requiredwith Polar checkout URL when paywall is enabled and entitlement is missing.
- Cloud launches return
GET /v1/workers/:id- Includes latest instance metadata when available.
POST /v1/workers/:id/tokensDELETE /v1/workers/:id- Deletes worker records and attempts to suspend the backing cloud service when destination is
cloud.
- Deletes worker records and attempts to suspend the backing cloud service when destination is
CI deployment (dev == prod)
The workflow .github/workflows/deploy-den.yml updates Render env vars and deploys the service on every push to dev when this service changes.
Required GitHub Actions secrets:
RENDER_API_KEYRENDER_DEN_CONTROL_PLANE_SERVICE_IDRENDER_OWNER_IDDEN_DATABASE_URLDEN_BETTER_AUTH_SECRET
Optional GitHub Actions secrets (enable GitHub social sign-in):
DEN_GITHUB_CLIENT_IDDEN_GITHUB_CLIENT_SECRET
Optional GitHub Actions variable:
DEN_RENDER_WORKER_PLAN(defaults tostandard)DEN_RENDER_WORKER_OPENWORK_VERSION(defaults to0.11.113)DEN_BETTER_AUTH_URL(defaults tohttps://app.openwork.software/api/den)DEN_CORS_ORIGINS(defaults tohttps://app.openwork.software,https://api.openwork.software,<render-service-url>)DEN_RENDER_WORKER_PUBLIC_DOMAIN_SUFFIX(defaults toopenwork.studio)DEN_RENDER_CUSTOM_DOMAIN_READY_TIMEOUT_MS(defaults to240000)DEN_VERCEL_API_BASE(defaults tohttps://api.vercel.com)DEN_VERCEL_TEAM_ID(optional)DEN_VERCEL_TEAM_SLUG(optional, defaults toprologe)DEN_VERCEL_DNS_DOMAIN(defaults toopenwork.studio)DEN_POLAR_FEATURE_GATE_ENABLED(true/false, defaults tofalse)DEN_POLAR_API_BASE(defaults tohttps://api.polar.sh)DEN_POLAR_SUCCESS_URL(defaults tohttps://app.openwork.software)DEN_POLAR_RETURN_URL(defaults toDEN_POLAR_SUCCESS_URL)
Required additional secret when using vanity worker domains:
VERCEL_TOKEN