Skip to content

kriscfoster/multi-language-bazel-monorepo

Repository files navigation

multi-language-bazel-monorepo

Getting Started with Bazel

I wanted to try to set up a multi-language monorepo using bazel for experimentation purposes. You can follow the journey on YouTube.

  1. Bazel Tutorial: (Part 1) Getting Started, Bazelisk & our First Build Targets.
  2. Bazel Tutorial: How to Build, Run, Test & Query (deps, rdeps, tags).
  3. Bazel Tutorial: Python targets with py_library, py_test, py_binary (internal & external deps).
  4. GitHub Actions for Bazel Monorepo - Building & Testing (CI).
  5. Bazel & Go Tutorial: Targets with go_library, go_test & go_binary (internal & external deps).
  6. Bazel & NodeJS Tutorial: library, test & nodejs_binary (internal & external deps).
  7. Bazel & Docker Tutorial: Building container images with bazel (local & remote registry).
  8. Deploying from a Bazel Monorepo to Heroku.
  9. Using Gazelle to Improve Multi-Language Bazel Monorepo.
  10. Bazel & Java Tutorial: java_library & java_binary (internal & external dependencies).
  11. Bazel & Docker: Using Custom Base Images.

Prerequisites

Useful Commands

Updating npm dependencies from package.json

  • bazel run -- @pnpm//:pnpm i --dir $PWD

Build all targets

  • bazel build //...

Test all test targets

  • bazel test //...

Sync Go Dependencies with go.mod

  • bazel run //:gazelle-update-repos

Format BUILD.bazel files (completely generates BUILd.bazel files for go projects)

  • bazel run //:gazelle

Run Python web app

Run Go web app

Run NodeJS web app

Run TypeScript app

  • bazel run //projects/ts_app

Build & Run NodeJS web app docker image

➜ bazel run projects/node_web:oci_tarball
...
Loaded image: projects/node_web:oci_tarball
...
➜ docker run -p 8080:8080 projects/node_web:oci_tarball
...
listening on port 8080

Build & Run Go web app docker image (amd64)

➜ bazel run projects/go_web:oci_tarball_amd64
...
Loaded image: projects/go_web:oci_tarball_amd64
➜
➜ docker run projects/go_web:oci_tarball_amd64
2023/08/27 13:40:22 running program's operating system target: linux
2023/08/27 13:40:22 running program's architecture target: amd64
2023/08/27 13:40:22 Going to listen on port: 8080

Build & Run Go web app docker image (arm64)

➜ bazel run projects/go_web:oci_tarball_arm64
...
Loaded image: projects/go_web:oci_tarball_arm64
➜
➜ docker run projects/go_web:oci_tarball_arm64
2023/08/27 13:40:58 running program's operating system target: linux
2023/08/27 13:40:58 running program's architecture target: arm64
2023/08/27 13:40:58 Going to listen on port: 8080

Deploying Go web app to Heroku

➜ bazel run projects/go_web:bazoku-deployment --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64
...

Publishing Multi-arch Docker image to DockerHub

➜ bazel run examples/multi_arch_go:publish
...
2023/08/18 16:41:38 registry.hub.docker.com/krisfoster96/monorepo-go-web:6: digest: sha256:c50ffe127f340301993cbc323e510211d6dab9a547aa1b1a81035426e4e9d1b1 size: 648
➜ docker buildx imagetools inspect registry.hub.docker.com/krisfoster96/monorepo-go-web:6
Name:      registry.hub.docker.com/krisfoster96/monorepo-go-web:6
MediaType: application/vnd.oci.image.index.v1+json
Digest:    sha256:c50ffe127f340301993cbc323e510211d6dab9a547aa1b1a81035426e4e9d1b1
           
Manifests: 
  Name:      registry.hub.docker.com/krisfoster96/monorepo-go-web:6@sha256:18b8c8a2606c3daf70a86db275c850080353bf5bd79a7045cca6732736b693c3
  MediaType: application/vnd.oci.image.manifest.v1+json
  Platform:  linux/arm64
             
  Name:      registry.hub.docker.com/krisfoster96/monorepo-go-web:6@sha256:fbc6e9ca088bbb683c0743b16aa98b51583e7af8564febd26154e638b12b484a
  MediaType: application/vnd.oci.image.manifest.v1+json
  Platform:  linux/amd64
➜ docker run --platform linux/arm64 registry.hub.docker.com/krisfoster96/monorepo-go-web:6
...
2023/08/18 15:56:08 running program's operating system target: linux
2023/08/18 15:56:08 running program's architecture target: arm64
2023/08/18 15:56:08 Going to listen on port: 8080
➜ docker run --platform linux/amd64 registry.hub.docker.com/krisfoster96/monorepo-go-web:6
...
2023/08/18 15:56:08 running program's operating system target: linux
2023/08/18 15:56:08 running program's architecture target: amd64
2023/08/18 15:56:08 Going to listen on port: 8080

About

Experimenting with bazel & multiple languages in a monorepo.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published