liveBook · Manning

Monorepo

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A monorepo is a single source-code repository that contains multiple services, applications, or related projects managed together.

A monorepo is a single code repository containing multiple projects. For a small microservices application, placing each service in its own subdirectory keeps the initial development infrastructure simple while keeping the complete application together. section 10.4.3 section 12.2.2

A shared repository does not have to mean a shared deployment schedule. Give each microservice its own continuous deployment (CD) workflow, scoped to its subdirectory. GitHub Actions can run the relevant workflow when that service changes, avoiding a rebuild and redeployment of every service. section 12.2.2 section 10.10.4

A gateway deployment workflow

In the FlixTube monorepo, separate GitHub Actions YAML files live in .github/workflows. The gateway workflow watches gateway/** on pushes to main and can also be run manually. Its deployment steps delegate work to shell scripts. section 10.10.4

Listing 10.16 Enabling a separate CD pipeline for the gateway
name: Deploy gateway                                        #1
 
on:
  push: 
    branches:
      - main                                                #2
    paths:
      - gateway/**                                          #3
 
  workflow_dispatch:                                        #4
 
jobs:
  deploy:
    runs-on: ubuntu-latest
   
    env:
      VERSION: ${{ github.sha }}                            #5
      CONTAINER_REGISTRY: ${{ secrets.CONTAINER_REGISTRY }}
      REGISTRY_UN: ${{ secrets.REGISTRY_UN }}
      REGISTRY_PW: ${{ secrets.REGISTRY_PW  }}
      NAME: gateway
      DIRECTORY: gateway                                    #5
 
    steps:
      
      - uses: actions/checkout@v3
 
      - name: Build
        run: ./scripts/cd/build-image.sh                    #6
 
      - name: Publish
        run: ./scripts/cd/push-image.sh                     #7
 
      - uses: tale/kubectl-action@v1                        #8
        with:
          base64-kube-config: ${{ secrets.KUBE_CONFIG }}
          kubectl-version: v1.24.2
      
      - name: Deploy
        run: ./scripts/cd/deploy.sh                         #9

Inspect the gateway workflow’s path scope, manual trigger, environment variables, and deployment steps. section 10.10.4

Keep the monorepo while it remains manageable. As the application and team grow, developers may encounter more merge conflicts, broken builds, and difficulty managing a large codebase. A direct-to-production workflow may also need a testing environment to buffer work in progress from customers. section 12.2 section 12.2.2

When the repository becomes restrictive, extract services into separate repositories. One approach is to run git init for each new repository, copy the service code and its deployment code, and commit it. Shared Terraform infrastructure code can have its own repository. If existing history matters, Git’s filter-branch command with --subdirectory-filter is an option to investigate. section 12.2.3 section 12.2.2

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains service layout, independent deployment workflows, growth tradeoffs, and steps for splitting repositories.
Examples
Uses FlixTube’s service subdirectories and gateway workflow to illustrate the structure and deployment setup.
What you can do after
Operate/configure GitHub Actions workflows scoped to individual service directories for independent deployment.
How it connects
Connects microservices with continuous deployment, independent deployment schedules, version history, and infrastructure as code.

Also explained in

Compare how 3 books explain monorepo →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.