$30 off During Our Annual Pro Sale. View Details »

The Monorepo - Storing your source code has never been so much fun

The Monorepo - Storing your source code has never been so much fun

Talk from Velocity about using a monorepo to store source code. Focus on usage in smaller organisations and whether monorepos scale down as well as up. Useful list of tools which help support storing all of your code in one place.

Gareth Rushgrove

October 19, 2017
Tweet

More Decks by Gareth Rushgrove

Other Decks in Technology

Transcript

  1. Gareth Rushgrove
    The Monorepo
    Storing your source code has
    never been so much fun

    View Slide

  2. View Slide

  3. @garethr

    View Slide

  4. - A recent history of code organisation
    - The cost of a new repo
    - Monorepo examples
    - Build tools for monorepos

    View Slide

  5. A recent history
    Of code organization

    View Slide

  6. A single team with a
    monolithic application
    in a single repository

    View Slide

  7. Multiple teams sharing a
    monolithic application in a
    single repository

    View Slide

  8. Multiple teams with
    separate applications in
    a single repository

    View Slide

  9. Multiple teams with
    separate applications in
    separate repositories

    View Slide

  10. Multiple teams with many
    separate applications in many
    separate repositories

    View Slide

  11. Multiple teams with many
    separate applications
    microservices in many
    separate repositories

    View Slide

  12. A single team with
    many microservice
    in many repositories

    View Slide

  13. Many teams with
    many applications in
    many repositories

    View Slide

  14. Many teams with
    many applications in
    one big Monorepo

    View Slide

  15. Enter monorepo
    What if we aimed for fewer repositories

    View Slide

  16. Monorepo:
    A repository which contains
    more than one logical project

    View Slide

  17. In some cases the monorepo
    contains nearly all of the
    projects in a given organisation

    View Slide

  18. The point is not that you should
    have a single project, but that
    one repository can contain
    multiple distinct projects
    David R. MacIver

    View Slide

  19. Why

    View Slide

  20. - Simplified organisation
    - Simplified dependencies
    - Tooling
    - Cross-project changes
    https://danluu.com/monorepo/

    View Slide

  21. - Single lint, build, test process
    - Easy to coordinate changes
    - Single place to report issues
    - Easier to setup dev environment
    - Integration tests
    https://github.com/babel/babel/blob/master/doc/design/monorepo.md

    View Slide

  22. You can make atomic
    refactors across the entire
    codebase without worrying
    about versioning issues
    Ben Maurer, Facebook

    View Slide

  23. Embrace change

    View Slide

  24. All of the above benefits
    of having one repository
    also extend to having
    fewer repositories
    David R. MacIver

    View Slide

  25. The cost of a new repo
    Downsides of so many code repositories

    View Slide

  26. It’s very easy to press the button

    View Slide

  27. 24 million users on GitHub
    have 67 million repos
    Octoverse 2017

    View Slide

  28. New repos spring into
    existence every day without
    you even knowing about it.
    Microsoft

    View Slide

  29. Juggling a multimodule
    project over multiple repos is
    like trying to teach a newborn
    baby how to ride a bike
    https://github.com/babel/babel/blob/master/doc/design/monorepo.md

    View Slide

  30. If project A depends on library
    B, you have to encode which
    revision of library B you use.
    Ben Maurer, Facebook

    View Slide

  31. Worse, if Project A also depends
    on C and D both of which use
    library B you have to ensure that
    the version of B that C and D
    depend on are compatible.
    Ben Maurer, Facebook

    View Slide

  32. - End-to-end testing
    - Running whole applications locally
    - Is that repository used?
    - Implicit dependencies in CI config
    - High cost of onboarding
    Roman Heinrich, Monorepos - Why and How

    View Slide

  33. Examples
    Observations from public and private repos

    View Slide

  34. Huge companies often talk
    about their monorepos

    View Slide

  35. People from huge companies
    often talk about their monorepos

    View Slide

  36. Google (computer science version)

    View Slide

  37. Google (business version)

    View Slide

  38. Scaling Mercurial at Facebook

    View Slide

  39. Microsoft claim the largest git repo on the planet

    View Slide

  40. There are two sides to Google
    Infrastructure for Everyone Else

    View Slide

  41. I’m more interested in
    Smaller teams and organisations,
    open source projects and widely
    available tools

    View Slide

  42. Put another way
    Do monorepos scale down as
    well as scale up?

    View Slide

  43. foresquare public monorepo

    View Slide

  44. foursquare/fsqio
    16 contributors, 15
    components, 3 languages

    View Slide

  45. At Puppet we ran a small
    experiment. 1 team.
    6 people. 7 components.
    4 languages.

    View Slide

  46. Tools for monorepos
    Build tools, migration and SaaS

    View Slide

  47. How do monorepos affect tooling?

    View Slide

  48. Build tools

    View Slide

  49. Most build systems start small
    and simple, but over time grow
    into hairy monsters that few
    dare to touch
    Mokhov, Mitchell, Peyton Jones, Marlow

    View Slide

  50. Non-recursive Make considered harmful

    View Slide

  51. Buck from Facebook

    View Slide

  52. BUCK file
    java_binary(
    name = "hello-buck-java",
    main_class = "com.facebook.buck.demo.HelloBuckJava",
    deps = [":main"],
    )
    java_library(
    name = "main",
    srcs = glob(["*.java"]),
    )

    View Slide

  53. Pants from Twitter

    View Slide

  54. Pants BUILD file
    python_library(
    name = 'pants',
    sources = globs('*.py'),
    dependencies = [
    '3rdparty/python:pantsbuild.pants',
    ],
    )

    View Slide

  55. Bazel from Google

    View Slide

  56. Bazel BUILD file
    cc_library(
    name = "hello-greet",
    srcs = ["hello-greet.cc"],
    hdrs = ["hello-greet.h"],
    )
    cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
    ":hello-greet",
    ],
    )

    View Slide

  57. I Make
    We used Make

    View Slide

  58. At smaller scale picking one
    build tool is probably more
    important than which one

    View Slide

  59. Migration tools

    View Slide

  60. You can move from
    multi-repos to a monorepo,
    without losing history or
    work-in-progress

    View Slide

  61. tomono - create a monorepo from many repos

    View Slide

  62. Maintain history from separate repos with tomono
    $ cat repos.txt
    [email protected]:mycompany/service-one.git one
    [email protected]:mycompany/service-two.git two
    [email protected]:mycompany/service-three.git three
    $ cat repos.txt | tomono.sh

    View Slide

  63. You can keep your
    monorepo private and still
    engage with open source

    View Slide

  64. split.sh - split a repository into read-only repos

    View Slide

  65. fbshipit - copy commits between repositories

    View Slide

  66. JavaScript Monorepos

    View Slide

  67. Oao - Javascript monorepo management tool

    View Slide

  68. Yarn workspaces for monorepos

    View Slide

  69. Rush from Microsoft

    View Slide

  70. Lerna - a tool for managing Javascript monorepos

    View Slide

  71. SaaS products

    View Slide

  72. GitHub code owners

    View Slide

  73. CODEOWNERS.md
    # Lines starting with '#' are comments.
    # Each line is a file pattern followed by one or more owners.
    # These owners will be the default owners for everything in the repo.
    * @garethr
    # Order is important. The last matching pattern has the most
    precedence.
    # So if a pull request only touches javascript files, only these
    owners
    # will be requested to review.
    *.js @octocat @github/js
    # You can also use email addresses if you prefer.
    docs/* [email protected]

    View Slide

  74. Travis CI added Build Stages

    View Slide

  75. Explicit build matrix in Travis
    matrix:
    include:
    - go: 1.8
    language: go
    install: cd consumer
    script:
    - make dependencies test
    - jdk: oraclejdk8
    language: clojure
    services: docker
    install: cd reporter
    script:
    - make ensure-table test
    - python: 3.6
    language: python
    install: cd data
    script:
    - make test
    - services: docker

    View Slide

  76. Conclusions
    If all you remember is...

    View Slide

  77. Monorepos are not just for
    Google, Facebook and
    Microsoft and Twitter

    View Slide

  78. Learn monorepo and multi-repo
    approaches to find out what
    works best for you

    View Slide

  79. No silver bullet
    Fred Brooks

    View Slide

  80. I’d argue that we don’t really yet
    have a good handle on how to
    scale that area that exists at the
    intersection of engineering and
    human organization
    Peter Seibel, Twitter

    View Slide

  81. Code organisation will only
    get more important as more
    people write ever more code

    View Slide

  82. Any questions?
    And thanks for listening

    View Slide