Giter VIP home page Giter VIP logo

go-bazel's Introduction

go-bazel

A Bazel scaffold template for golang / protobuf+grpc mono repository.

Features

  • Multi golang microservices in the mono repo
  • Single build pipeline
  • Shared golang library
  • Shared grpc/protobuf library
  • Automatic release GitHub workflow action
    • macOS and Linux builds

A hypothetical setup

  • A cli ServiceA calling ServiceB grpc method Sum(int32, inte32)
  • A ServiceB serving the Sum method over grpc.

Step 1: Install Bazel

Step 2: Build it

Run the complete build pipeline using:

bazel build //...

Note: The first build will take a moment. No worries, you will see the Bazel mono repo benefits later.

Step 3: Run to see the result

In one terminal, run the grpc serving ServiceA:

bazel run services/servicea :42042

In another terminal, run the client ServiceB:

bazel run services/serviceb :42042

You should see the result. Protobuf + grpc built, services binaries built as well. The built binaries are in the /bazel-bin directory in their respective sub directories.

Protobuf/grpc caveats

There is a little caveat with proto when using Bazel. The golang generated proto files are in the bazel-bin build folder (as they are result of the build, not a source). So they are not accessible to your IDE. There is an official issue. Until solved, the workaround is:

  • For every proto service:

  • Run Bazel to generate the proto golang implementation:

    bazel run //proto/[service]
  • Manually copy generated implementation back to the proto/[service] directory:

    cp ./bazel-bin/proto/[service]/[service]_go_proto_/github.com/jankremlacek/go-bazel/proto/[service]/*.pb.go ./proto/[service]/
  • Also, you have to exclude the copied file from the Bazel build. Create file /proto/[service]/.bazelignore and put there all generated [filename].pb.go files.

Note: Of course, this process can be automated.

Additonal commands

  • Build BUILD.bazel build files using Gazelle:
    bazel run //:gazelle
  • Update Gazelle golang dependencies using:
    bazel run //:gazelle-update-repos
  • Test whole pipeline using:
    bazel test //...

Additional resources

go-bazel's People

Contributors

jankremlacek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.