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
Kevin
Kevin3w ago
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?
Tristan
TristanOP3w ago
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 integration
Kevin
Kevin3w ago
if they all use the same bindings then why don't you just attach multiple domains to the same worker?
Tristan
TristanOP3w ago
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)
Kevin
Kevin3w ago
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
Kevin
Kevin3w ago
Cloudflare Docs
Advanced setups
Learn how to use Workers Builds with more advanced setups
Tristan
TristanOP3w ago
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 🤞
Kevin
Kevin3w ago
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
Gab
Gab2w ago
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
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.

Did you find this page helpful?