title: Bazel - Build, Push, Deploy Docker Containers to Kubernetes within Monorepo
body: <p>I have a monorepo with some backend (<a href="https://nodejs.org/" rel="noreferrer">Node.js</a>) and frontend (<a href="https://angular.io/" rel="noreferrer">Angular</a>) services. Currently my deployment process looks like this:</p>
  
  <ol>
  <li>Check if tests pass</li>
  <li>Build docker images for my services</li>
  <li>Push docker images to container registry</li>
  <li>Apply changes to Kubernetes cluster (<a href="https://cloud.google.com/kubernetes-engine/" rel="noreferrer">GKE</a>) with <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/" rel="noreferrer">kubectl</a></li>
  </ol>
  
  <p>I'm aiming to automate all those steps with the help of <a href="https://bazel.build/" rel="noreferrer">Bazel</a> and <a href="https://cloud.google.com/cloud-build/" rel="noreferrer">Cloud Build</a>. But I am really struggling to get started with Bazel:</p>
  
  <p>To make it work I'll probably need to add a <code>WORKSPACE</code> file with my external dependencies and multiple <code>BUILD</code> files for my own packages/services? <em>I need help with the actual implementation:</em></p>
  
  <ol>
  <li>How to build my Dockerfiles with Bazel?</li>
  <li>How push those images into a registry (preferably <a href="https://cloud.google.com/container-registry/" rel="noreferrer">GCR</a>)?</li>
  <li>How to apply changes to Google Kubernetes Engine automatically?</li>
  <li>How to integrate this toolchain with Google Cloud Build?</li>
  </ol>
  
  <h1>More information about the project</h1>
  
  <blockquote>
    <p>I've put together a tiny <a href="https://github.com/flolude/learning-bazel-monorepo" rel="noreferrer">sample monorepo</a> to showcase my use-case</p>
  </blockquote>
  
  <h3>Structure</h3>
  
  <pre><code>├── kubernetes
  ├── packages
  │   ├── enums
  │   ├── utils
  └── services
      ├── gateway
  </code></pre>
  
  <h3>General</h3>
  
  <ul>
  <li><code>Gateway</code> service depends on <code>enums</code> and <code>utils</code></li>
  <li>Everything is written in Typescript</li>
  <li>Every service/package is a Node module</li>
  <li>There is a <code>Dockerfile</code> inside the <code>gateway</code> folder, which I want to be built</li>
  <li>The Kubernetes configuration are located in the <code>kubernetes</code> folder.</li>
  <li>Note, that I don't want to publish any <code>npm</code> packages!</li>
  </ul>