Published in


Using Cirrus CLI instead of Makefiles for gRPC code generation

Cirrus CLI is a tool for running containerized tasks reproducibly in any environment. Most commonly, Cirrus tasks are used as part of continuous integration workflows but Cirrus tasks can also be used as part of the local development process as a hermetic replacement of helper scripts/Makefiles that don’t rely on locally installed packages. In this post we’ll see how the boilerplate of generating gRPC definitions for Go can benefit from using Cirrus CLI.

First, let’s start with taking a closer look at the recommended way of generating gRPC definitions from the official documentation. It seems like a lot of boilerplate.

There is a need to preinstall protobuf compiler and two Go packages. Note that in the documentation versions of the protobuf compiler and Go packages are not pinned! As a result on your local workstation will always get the latest versions at the time of the first installation which most likely will be completely different from the versions of your colleague that did the setup a few months earlier.

With Cirrus CLI one can use a Docker container with a pinned version of protobuf compiler and Go packages. You can either create such a Docker image yourself or use some existing one, for example, namely/protoc . Let’s see how .cirrus.yml configuration file with a generation task will look like:

name: Generate
# To not run in Cirrus CI cloud.
# namely/protoc image tagged with a desired gRPC version.
# The image will also contain the latest protoc
# at the time of image creation.
image: namely/protoc:1.15_0
- cd examples/helloworld/helloworld
- -d . -o . -l go --go-source-relative

Simple as that! Now you have reproducible generation of gRPC definition regardless of what version of protobuf compile, Go and gRPC plugins you have locally installed.

To run Generate task simply type cirrus run generate --dirty in your terminal.

Cirrus Run Example (1/3 speed)

By default, Cirrus CLI runs every task on a copy of your project files. The --dirty flag forces👌 the CLI just to mount your project directory in order to persist any changes made by the task run.

We are encouraging everyone to try out Cirrus CLI. You can run it locally or integrated with any CI. A list of tested CI configurations can be found here.

And please send us feedback either on GitHub or on Twitter!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store