6 ms·
kind of an aside, but what's the best practice for pushing and building separate projects in a monorepo? say you have a structure like: projectA projectB
by endisneigh 6y ago
kind of an aside, but what's the best practice for pushing and building separate projects in a monorepo?
say you have a structure like:
projectA
projectB
sharedUtils
Each time you push you might have a build for projectA and projectB but it builds both each time you push to master. Ideally you could use Git to see if anything in projectA or sharedUtils changed to trigger projectA's build and same for projectB, but I'm curious what others are doing.
- simias 6y agoIf separate projects have independent builds maybe a monorepo was not a great idea to begin with? I have a big monorepo at work but whenever anything changes I want to rebuild everything to generate a new firmware image. I have ccache setup to speedup the process given that obviously only a tiny fraction of the code actually needs to be rebuilt. It's a bit wasteful, sure, but if I were to optimize it I'd be worried about ending up with buggy, non-reproducible builds. Easier to just recompile everything every time and make sure everything still works the way you expect. So basically my approach is KISS, even if it means longer build times.
- dgellow 6y agoIIRC you can specify filters "paths" and "paths-ignore" when you define a github action that should only be triggered when a subdirectory changes. See this documentation page: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths https://docs.github.com/en/actions/reference/workflow-syntax... Their example is: on: push: paths: - '\*.js' but I believe you can also specify the subdirectory you care about.
- numbsafari 6y agoPerhaps check out a tool like please[1]. There are other tools in this space, but that one has worked well for me without the complexity of some other, similar tools. [1] https://please.build https://please.build
- oftenwrong 6y agoI can't speak for using it in a massive monorepo, but I started using https://please.build https://please.build for some of my personal projects recently just as an alternative to the dominant Java build systems (Ant/Maven/Gradle). It's far more straightforward to use, and incremental builds actually work reliably.
- jrockway 6y agoThat's what build systems aim to do, and there are many of them. In general, I've found all the tooling required around monorepos to be a job for a full-time team. Shortcuts (as suggested in other replies) or full builds on every commit tend to stop scaling relatively quickly. If you take shortcuts, you will find that it becomes "tribal knowledge" to do a full build every time you edit a single line of code, and people who were once making multiple changes a day start making one change a week, or they start committing code without ever having run it. (It happened to me on a 4 person team. We had so many things that needed to be running to test your app, that people just started committing and pushing to production without ever having run their changes locally! That is the kind of thing that happens if you stop caring about tooling, and it happens fast. I addressed it by taking a couple of days to start up the exact environment locally in a few seconds, without a docker build, and people started running their code again.) Be very, very careful. If you do a full build on every commit, it gets slow much sooner than you'd expect, and people are going to do less work while they context switch to posting to HN while waiting for their 15 minute build for a 1 line code change. I worked at Google and we had a monorepo, and there were hundreds if not thousands of engineers working on build speed and developer productivity, and it was still significantly slower to "bazel run my-go-binary" versus "go run cmd/my-go-binary". In many cases, it was worth it, but in very isolated applications, it was definitely not worth it. (And people did work around it, by just setting up Git somewhere and using Makefiles or whatever, and that ended up being even worse. But it gets worse incrementally over time, and you're kind of the frog getting boiled alive.) Where I'm going with is to advise you to be very careful. The tools to support real productivity in a monorepo are expensive in terms of your org's time. If you can get by with a repo per app and a common modules repo, and just update the app to refer to a version of the modules repo as though it's some random open source project you depend on, you're going to get much farther with much less tooling work than you would with a monorepo. But, the modules repo is going to break apps without knowing, and that's going to be a pain. Monorepos do exist for a good reason. (The other thing I like about monorepos is that you do less per-project setup work. Want to make some new app? You can just start writing it, and you get the build, deploy, framework, etc. for free. It can be very productive if you're finding yourself starting new projects regularly. In my spare time, I write a software, and I really regret splitting it up into multiple projects. But, it's kind of necessary for open source stuff -- people don't want to download ekglue if they want to just run jlog. So I split them, but it costs me my valuable free time to do something I've already done ;) My TL;DR is that you will be tempted to take shortcuts and the shortcuts will suck. If your project has the resources to have someone set up Bazel, distribute the right version of Bazel and the JRE to developer workstations, setup CI that is aware of Bazel artifact caching, and SREs to be around 24/7 to support your now-custom build environment, you will have a good experience. Be aware that a monorepo is that level of investment. Meanwhile, if you just have a frontend and a backend in the same repo, you can probably get away with a full build for every commit. And you don't need that shadow team of tooling engineers to make it work, you just need a docker build, and a script that runs "go test ./... && npm test" or whatever ;)
- alfalfasprout 6y agoAs a few others have mentioned this is something that build systems handle since they understand the dependency graph. For example, Bazel is often used to this end. However... I would strongly advise not going for a monorepo. No, I don't mean something like tensorflow where you have a bunch of related tools and projects in a single repo. I mean one repo for the entire org where totally unrelated projects live. Every company I've been at that used a monorepo found themselves struggling to make it work since you need a ton of full time engineers just to keep things working and scaling. Many of the problems that monorepos try to solve (simplifying dependency and version management) are traded for 10x as many problems and many of them are hard (incremental builds, dependency resolution). Google has a huge team in charge of helping their monorepo scale and work efficiently. You are not google... don't be tempted.
- benreesman 6y agoI'll try to tread at least a little lightly here because this topic does tend to be a bit flammable, but caveat emptor. My contrasting anecdotal experience is that whether at BigCo or on a small team monorepo is almost always the right answer until your requirements get exotic enough that you're in special-case land anyways (like a separate repo for machine-initiated commits, or something that's security-sensitive enough to wall off some contributors). Both `git` and `hg` scale easily to to really big projects if you're storing text in them (at FB our C++ code was in a `git` monorepo on stock software until like 2014 or something before it started bogging down, I'll gloss over the numbers but, big): the monorepo-scaling argument is brought out a lot but rarely quantified. The multi-repo problem that gets you is dependency management, which in the general case requires a SAT-solver (https://research.swtch.com/version-sat https://research.swtch.com/version-sat), but of course you don't have a SAT-solver in your build script for your small-to-medium organization, so you get some half-assed thing like what `pip` and `npm` do. Again purely anecdotal, but in my personal experience multi-repo too often gets pushed by folks who want to make their own rules for part of the codebase ("the braces go here"), push an agenda around unnecessary RPCs, or both. That's not true of all cases of course, but it's a common enough antipattern to be memorable.
- adsfoiu1 6y agoI personally have seen the opposite problem - the friction of making small changes to "utility" libraries becomes a huge pain point for developers when you have to make changes, test locally, push to package manager, update all consumers to use the new version... It's much easier, in my experience, to just consume a class that's already in the same project / repo.
- zdw 6y agoMonorepos require much more care to be put into the integration/CI side of the process. This is worth a read: https://yosefk.com/blog/dont-ask-if-a-monorepo-is-good-for-you-ask-if-youre-good-enough-for-a-monorepo.html https://yosefk.com/blog/dont-ask-if-a-monorepo-is-good-for-y...
- jeffbee 6y agoThat argument is super, super weird. I agree that if you are a complete jackass with a demonstrated tendency to make poor choices, a monorepo may not work well for you. On the other hand, software development is probably not the right career for such a defective person, or the right line of business for such a defective organization. The anti-pattern described at the beginning of the article is why you should adopt trunk-based development, not a good argument for why you should avoid monorepos. https://trunkbaseddevelopment.com/ https://trunkbaseddevelopment.com/
- zdw 6y agoTrunk based development is definitely the ideal, and the mode of operation forced on users of Gerrit/Repo, which tries to implement much of Google's internal monorepo workflow with multiple external standalone repos. The main point is the "better tooling than average" section near the end - you need tools that can understand relationships between different parts of the codebases, and test appropriately, which is where the integration process for monorepos starts to fall apart.
- ojkelly 6y agoIf you’re in the Javascript/Typescript world Yarn 2 does a really good job with local packages, and letting you depend on them, and optionally allowing you to push for soundness in your repo. (vendoring your deps, tooling, and declaring all dependencies). Building on that dependency graph and soundness in Yarn 2, I built yarn.build [0] which works in a similar way to all the monorepo build tools. It builds your packages based on their dependency graph, skips whats already built, and has a bundle command for creating a zip ready for lambda/docker/etc [0] https://yarn.build https://yarn.build