Can I run two workers from one monorepo?

I'm sure the answer is yes; I'm just wondering what the set up here would look like. If my repo was:
| worker1/
| - <all worker 1 files here - src/, wrangler.toml, etc.>
| worker2/
| - <ditto for worker 2>
| worker1/
| - <all worker 1 files here - src/, wrangler.toml, etc.>
| worker2/
| - <ditto for worker 2>
...how would I configure the action to read from those two top-level directories and build two distinct workers? Or would I need some sort of top-level Wrangler file? Just unable to visualise this.
8 Replies
Craig
Craig2d ago
You might be looking for Service Bindings (assuming you want to talk to the other worker) https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/
Cloudflare Docs
Service bindings - RPC (WorkerEntrypoint) · Cloudflare Workers docs
Facilitate Worker-to-Worker communication via RPC.
Mitya
MityaOP2d ago
Sorry, not quite. I don't want one worker to talk to another. I just want two distinct workers to be managed from a monorepo. Right now I have a GH action which handles my worker deploy, but the worker assumes my repo is a single worker. I want that repo to contain two workers.
texan
texan22h ago
Cloudflare Docs
Advanced setups · Cloudflare Workers docs
Learn how to use Workers Builds with more advanced setups
mw10013
mw1001321h ago
I created an OpenAuth wrangler example that has 2 workers in a monorepo that may be helpful: https://github.com/mw10013/openauth-wrangler There seem to be many ways to skin this cat so would be curious to know what you come up with.
GitHub
GitHub - mw10013/openauth-wrangler: OpenAuth server and client exam...
OpenAuth server and client example using wrangler. Contribute to mw10013/openauth-wrangler development by creating an account on GitHub.
Mitya
MityaOP12h ago
Thanks guys, I'll take a look at these resources 👍
darkpool
darkpool9h ago
Not sure if this is what you're asking about but I have all my workers (apps and apis) and packages (shared code like design library, typescript configs, helpers, db setup, etc.) in a monorepo using turborepo and pnpm workspaces. Each has a package.json and each worker has a wrangler config. they are separate entities and can share code through packages but each can be built and developed simultaneously by using turborepo. https://developers.cloudflare.com/workers/ci-cd/builds/advanced-setups/ https://turbo.build/repo/docs/crafting-your-repository/structuring-a-repository
Cloudflare Docs
Advanced setups · Cloudflare Workers docs
Learn how to use Workers Builds with more advanced setups
Turbo
Structuring a repository | Turborepo
Start by creating a repository using the conventions of the ecosystem.
darkpool
darkpool9h ago
if you want to setup preview deployments linked to git workflow you just need to go into worker settings on cloudflare dashboard and tell it where to run the deploy command.
No description
Mitya
MityaOP9h ago
Thanks, that's precisely what I'm after. Shortly before your message I found this page in the docs which also mentions Turborepo.

Did you find this page helpful?