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:
...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
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.
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.
Sounds like you want Workers builds 🙂
https://developers.cloudflare.com/workers/ci-cd/builds/advanced-setups/
Cloudflare Docs
Advanced setups · Cloudflare Workers docs
Learn how to use Workers Builds with more advanced setups
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.
Thanks guys, I'll take a look at these resources 👍
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.
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.