Building projects (CI/CD), instruments

In some projects, the build script is playing the role of Cinderella. The team focuses its main effort on code development. And the build process itself could be handled by people who are far from development (for example, those responsible for operation or deployment). If the build script works somehow, then everyone prefers not to touch it, and no one ever is thinking about optimization. However, in large heterogeneous projects, the build process could be quite complex, and it is possible to approach it as an independent project.If you treat the build script as a secondary unimportant project, then the result will be an indigestible imperative script, the support of which will be rather difficult.


In this note we will take look at the criteria by which we chose the toolkit, and in the next one — how we use this toolkit. (There is also a Russian version.)


CI/CD (opensource.com)


General model of project assembly


Project build model in all considered tools is a (DAG), and not a structural approach (when a procedure calls other procedures and then uses the results). This is due to the fact that during the development of the project, frequently minor changes are made and most no assembly operations required. That is, the organization of the project in the form of a digraph is the basis for performing only those actions which are necessary for the immediate task, thereby frequently used operations will execute promptly.


The nodes in the graph are either goals or tasks. Goals are the results to be achieved, and tasks are operations that need to be performed in order to achieve the current goal. A task can be executed only when all dependencies are satisfied.


Higher-level models are implemented on top of this basic model in some build tools.


Tool selection


In the beginning of a project, it is sometimes possible to predict how complex the integration of the project will be. In our case, it turned out that it was required to build several node.js modules, several go-lang modules, and deploy multiple interconnected terraform modules. None of the subprojects were JVM-based.


Other similar projects that have been evolving "organically" build is performed using make. In Makefiles one could find bash, perl, curl, php and other dedicated utilities. Such build mechanism is error prone, difficult to maintain, and it has rather poor performance.


For a new integration project we decided to try to find an alternative build tool. The following options were considered:



Make


This is a mature widespread program and allows implementing build scripts of large and complex projects.


Pros



Cons



When there are no constraints, one may find in build scripts:



These factors make maintenance more difficult and also make build process an unsafe operation.


Maven


Maven revolutionized build systems when it was first introduced. Ideas of declarative descriptions of projects, wide use of conventions, code reuse via plugins, storing artifacts in repositories, the use of an identification system, including versions — all this provided recognition and widespread use in many JVM projects to this day.


Pros



Cons



The lack of imperative scripts is both a plus and a minus. On the one hand, the declarative approach provides a strict separation of code and model, on the other hand, build tasks often require some small snippets of imperative logic, and solving such tasks in maven is painful.


Sbt


Sbt is a tool for building Scala projects. Appeared around the same time as gradle.


Pros



Cons



Sbt looks more like a niche tool for building Scala project rather than a universal tool for any project.


Gradle


Gradle appeared in 2007 as a response to the major limitations of Maven — the lack of imperative code, the difficulty of implementing plugins, and the inconvenience of performing non-standard operations. Gradle is based on the ideas proposed by Maven, develops them and changes the emphasis. The main parts of the gradle model are the following:



An important improvement was the use of DSL (domain specific language). The DSL is based on an imperative language, but actually provides the declarative model. Imperative tasks are of course easily solved due to the underlying language.


Pros



Cons



Dialect selection — gradle/groovy or gradle/kotlin


Gradle was originally used with groovy-DSL. Later Kotlin-based DSL was developed.


Kotlin pros



Cons



Conclusion


Based on the results of comparison of the available project build tools, we decided to try to implement the build and CI/CD in our project using gradle/kotlin. This option has a number of advantages in comparison with the implementation of the project build based on make/shell.


Gradle/kotlin vs make


Below are the comparative advantages of gradle/kotlin with respect to make:


Advantages:



Disadvantages:



In the next part, we'll look at some of the features of using gradle/kotlin to build non-JVM projects.


Acknowledgements


I would like to thank nolequen, Starcounter, tovarischzhukov for constructive criticism of the draft article.

@primetalk
05.04.2021 13:25 UTC
Первоисточник