How we are maintaining ProtoBuf (Protocol Buffers) at Nuclei

Piyush Mehta | Mon 2nd Mar, 2020

We at Nuclei, welcome the latest technologies in our stack. We have our Micro Services in Java and Go Lang. I as a Full Stack Developer got an opportunity to completely build this system for us.

GitHub Actions + GitHub Package Registry + gRPC

Problems which our solution solved!

  1. Getting Go and Java artifacts at a swoosh
  2. Cost effective practice
  3. Robust Architecture
  4. Managing protocol buffer definitions at ease
  5. Generating the appropriate language files from the definitions
  6. Following Semantic Versioning along with Pre-Releases.

Challenges we faced.

Managing proto files is a cumbersome task for both the user and the creator of the proto. Distributing it in a cost effective yet efficient method was another big task. Using JFrog Artifactory with Jenkins needed separate server to host.

How We Manage Protocol Buffer Files.

We have a monorepo known as Protorepo where we keep our latest protocol buffer files.

How do we build the Java and Go Lang code?

We are using GitHub Actions + GitHub Package Registry. When one creates a new release. Let’s say version V1.0.0. It triggers our GitHub Action which generates GitHub Packages (Artifacts for Java) available for the other projects and it even pushes new releases with same versions for Go Lang according to the project name.

How do we pull dependencies?

For java →

plugins {
    id("maven-publish")
}

publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/USERNAME/URL")
            credentials {
                username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
                password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
            }
        }
    }
    publications {
        gpr(MavenPublication) {
            from(components.java)
        }
    }
}

For Go: All the releases gets accumulated in a repository named Proto-gen. There all the Golang generated proto files are stored by releases. If a developer needs to use that proto file let’s say filename is foobar.pb.go. That project becomes a module in the Proto-gen **repository. To get it one has to just pull it using the url followed by the version *\example: go get github.com/example-org/foobar@v1.0*.0

For Go →

go get <URL of the release>
go get github.com/CDNA-Technologies/proto-gen/go/proto/master-data

How helpful it is?

  1. We are able to generate 30+ artifacts for Go as well as Java in less than 3 minutes.
  2. Building code and shipping it was never so quick and easy for us.
  3. All our Development Operations become even more easier.
  4. GitHub gives us storage and CI & CD minutes in our team plan, so why not use it.
  5. Data is safe and secured.

divider

Liked it? Why not share it with others