Benefits
Terrabuild ultimate goal is to ensure the build happens as fast as possible. There are two ways to make it fast:
- do not build what has not changed
- build several projects in batch
Terrabuild does both by leveraging a build cache and batch-building projects together.
Sample workspace
Imagine following projects and dependencies as follow. Projects are managed individually, and each have a dedicated PROJECT.
flowchart LR classDef default stroke:black classDef root stroke-width:2px classDef publish fill:skyblue classDef build fill:palegreen classDef batch fill:orange publishA("publish A\n@dotnet publish\n@docker build\n@docker push") --> buildA("build A\n@dotnet build") buildA --> buildC("build C\n@dotnet build") buildA --> buildD("build D\n@dotnet build") publishB("publish B\n@docker build\n@docker push") --> buildB("build B\n@npm build") class publishA,publishB root class publishA,publishB publish class buildA,buildB,buildC,buildD build
Caching
If a project does not need to be rebuilt, build artifacts are restored and dependants can be built in turn.
Even better: if a branch of the graph does not lead to new artifacts, it can be safely ignored in CI context (this is usually not the case locally where developers needs artifacts).
For eg: if project A, C and D do not change, Terrabuild won’t even bother restoring artifacts since no artifacts are generated in CI.
You need an account Insights if you want to leverage caching capabilities.
Batch build
Running small tasks is not efficient: this is why Terrabuild is able to group tasks together to make the build faster. You can focus on how to build project and Terrabuild will focus on optimizing the build graph the best it can transparently.
For instance, @dotnet build
tasks can be grouped together - post-build actions must still take place to cache artifacts as required:
flowchart LR classDef default stroke:black classDef root stroke-width:2px classDef publish fill:skyblue classDef build fill:palegreen classDef batch fill:orange classDef optimize stroke-width:2px,stroke-dasharray: 5 2 publishA("publish A\n@dotnet publish\n@docker build\n@docker push") publishA --> buildA("post-build A") publishA --> buildC("post-build C") publishA --> buildD("post-build D") batchBuildACD("batch-build A+C+D\n@dotnet build") buildA --> batchBuildACD buildC --> batchBuildACD buildD --> batchBuildACD publishB("publish B\n@docker build\n@docker push") --> buildB("build B\n@npm build") class publishA,publishB root class publishA,publishB publish class buildA,buildB,buildC,buildD build class batchBuildACD batch class buildA,buildC,buildD,batchBuildACD optimize