{"id":20838642,"url":"https://github.com/jankremlacek/go-bazel","last_synced_at":"2025-05-08T20:57:56.789Z","repository":{"id":60004176,"uuid":"539187193","full_name":"jankremlacek/go-bazel","owner":"jankremlacek","description":"Micro services monorepo Golang Bazel Gazelle example setup","archived":false,"fork":false,"pushed_at":"2023-12-23T19:49:32.000Z","size":51,"stargazers_count":93,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T20:57:51.866Z","etag":null,"topics":["bazel","gazelle","go","golang","grpc","grpc-client","grpc-go","grpc-server","microservice","microservices","monorepo","monorepository","protobuf","setup"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jankremlacek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-20T20:50:39.000Z","updated_at":"2025-04-28T10:10:47.000Z","dependencies_parsed_at":"2023-12-12T20:31:41.250Z","dependency_job_id":"6f22d4e5-d424-4127-928b-bf8b08e71632","html_url":"https://github.com/jankremlacek/go-bazel","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.21875,"last_synced_commit":"38a5e10e0480e7b2bed2adff0f815031014ac823"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankremlacek%2Fgo-bazel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankremlacek%2Fgo-bazel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankremlacek%2Fgo-bazel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jankremlacek%2Fgo-bazel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jankremlacek","download_url":"https://codeload.github.com/jankremlacek/go-bazel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253149568,"owners_count":21861719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","gazelle","go","golang","grpc","grpc-client","grpc-go","grpc-server","microservice","microservices","monorepo","monorepository","protobuf","setup"],"created_at":"2024-11-18T01:10:58.439Z","updated_at":"2025-05-08T20:57:56.770Z","avatar_url":"https://github.com/jankremlacek.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-bazel\n\nA Bazel scaffold template for `golang` / `protobuf+grpc` mono repository.\n\n## Features\n\n- Multi `golang` microservices in the mono repo\n- Single build pipeline\n- Shared `golang` library\n- Shared `grpc/protobuf` library\n- Automatic release GitHub workflow action\n    - macOS and Linux builds\n\n## A hypothetical setup\n\n- A cli `ServiceA` calling `ServiceB` grpc method `Sum(int32, inte32)`\n- A `ServiceB` serving the `Sum` method over grpc.\n\n### Step 1: Install Bazel\n\n- **macOS**: [https://bazel.build/install/os-x](https://bazel.build/install/os-x)\n- **Ubuntu**: [https://bazel.build/install/ubuntu](https://bazel.build/install/ubuntu)\n\n### Step 2: Build it\n\nRun the complete build pipeline using:\n\n```sh\nbazel build //...\n```\n\n\u003e **Note:** The first build will take a moment. No worries, you will see the Bazel mono repo benefits later.\n\n### Step 3: Run to see the result\n\nIn one terminal, run the grpc serving `ServiceA`:\n\n```sh\nbazel run services/servicea :42042\n```\n\nIn another terminal, run the client `ServiceB`:\n\n```sh\nbazel run services/serviceb :42042\n```\n\nYou should see the result. Protobuf + grpc built, services binaries built as well.\nThe built binaries are in the `/bazel-bin` directory in their respective sub\ndirectories.\n\n## Protobuf/grpc caveats\n\nThere is a little caveat with proto when using Bazel. The `golang` generated proto\nfiles are in the `bazel-bin` build folder (as they are result of the build, not a\nsource). So they are not accessible to your IDE. [There is an official issue](https://github.com/bazelbuild/rules_go/issues/512).\nUntil solved, the workaround is:\n\n- For every proto service:\n- Run Bazel to generate the proto `golang` implementation:\n\n  ```sh\n  bazel run //proto/[service]\n  ```\n\n- Manually copy generated implementation back to the `proto/[service]` directory:\n\n  ```sh\n  cp ./bazel-bin/proto/[service]/[service]_go_proto_/github.com/jankremlacek/go-bazel/proto/[service]/*.pb.go ./proto/[service]/\n  ```\n\n- 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.\n\n\u003e **Note:** Of course, this process can be automated.\n\n## Additonal commands\n\n- Build `BUILD.bazel` build files using [Gazelle](https://github.com/bazelbuild/bazel-gazelle):\n    ```sh\n    bazel run //:gazelle\n    ```\n- Update Gazelle `golang` dependencies using:\n    ```sh\n    bazel run //:gazelle-update-repos\n    ```\n- Test whole pipeline using:\n    ```sh\n    bazel test //...\n    ```\n\n---\n\n## Additional resources\n\n- [Bazel official website](https://bazel.build/)\n- [Bazel at GitHub](https://github.com/bazelbuild/bazel)\n- [Gazelle at GitHub](https://github.com/bazelbuild/bazel-gazelle)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankremlacek%2Fgo-bazel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjankremlacek%2Fgo-bazel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjankremlacek%2Fgo-bazel/lists"}