Best practices for deploying sites from monorepos?

Hi Joost!

TL;DR Monorepos are a bit hard for us to handle with code-based configuration at present and we are tracking that issue here: https://github.com/netlify/build-image/issues/196

Your statement of the limitations is correct:

  • netlify.toml is read from the root of the repo, so There Can Be Only One which makes for differing configuration of multiple sites to the same repo on the same branches very hard.
  • headers and redirects are not applied to contexts, though there is an only-slightly-convoluted workflow you could use to apply them PER DEPLOY instead, from code - if you construct them at build time into _redirects and _headers instead. Many customers use workflows like this one for doing “conditional” things at build and if your script were a bit smarter (checked something like DEPLOY_URL to discover the netlify sitename - Build environment variables | Netlify Docs) if could do this based on which SITE is being built instead.

So to answer your major question: “Short of going into the Netlify UI and configuring multiple sites for the same repo, what would be the best way to handle this?” I have a question - what is the config difference between the sites? If it is a small changeset, we could talk about how you could use the API to reconfigure the sites programatically.

We hope that our CI works for all customers for all use cases, but we know it doesn’t. We are working on a fix to the situation where we COULD read netlify.toml from the base directory you set on a site - but that still doesn’t really help in the way you mention - there would be additional config (of that base parameter) needed in our UI or via API. I’ve attached the URL for this thread to the open ticket for that work so I can ping back in case we ship the implementation of it.