How to deploy multiple workers (≠ domains) from the same repository (multi-tenant app)
Hello,
I would like to get a second version of an app i'm deploying on another domain, for another client.
The repository would be the same (same code, same branch) I would like to get other environnement variable for this client
And each time I would merge pull request on main, it would trigger a deployment using the cloudflare integration to both of the workers
Thanks
9 Replies
you can create wrangler config for each tenant and then deploy it using npx wrangler deploy --config tenant1.jsonc
does all tenants use the same bindings?
yes they'll use the same binding; I'd rather use the git integration automatic with cloudflare when I merge PR on main branch.
Each time i tried deploying the project using
npx wrangler deploy it ended up using dev env variable in prod and broke the prod twice
is there a way to keep using this integrationif they all use the same bindings then why don't you just attach multiple domains to the same worker?
because the environment variable needs to be different, mainly for
NEXT_PUBLIC_APP_URL (the domain on which the app runs, so emails are generated with the correct links)they support monorepos so you could have each tenant config in they own directory and configure that, not sure if that would work just thinking out loud
nope, thank you after reading it their example is about "prod" and "preview" environement, but then that should work with "client1" / "client2", just hoping the git integration will trigger a deploy on both 🤞
you can have each worker points to the same repo so it will start builing on any change there and change each worker build command to use diferent config file
or maybe you could use tenants as environments but you would still need to change the build command to use the correct environment
take a look at https://alchemy.run/
you can easyly manage/reuse your workers/pages, take a look at this example ->
https://github.com/oscabriel/better-chat/blob/main/alchemy.run.ts
if you want to duplicate your workers, just create new bindings, and add a new worker to your file, you can even deploy in parallel, easy managemnt, easy deploy, 1 command and 30 seconds and everything is up
Alchemy
Infrastructure as TypeScript
GitHub
better-chat/alchemy.run.ts at main · oscabriel/better-chat
better chat through durable objects. Contribute to oscabriel/better-chat development by creating an account on GitHub.