|
1 | 1 |
|
2 | 2 | # Use cases |
3 | 3 |
|
4 | | -## Workspaces in a mono-repo |
| 4 | +### Partial cloning |
5 | 5 |
|
6 | | -Multiple projects, depending on a shared set of libraries, can live together in a single repository. |
| 6 | +Reduce scope and size of clones by treating subdirectories of the monorepo |
| 7 | +as individual repositories. |
| 8 | + |
| 9 | +``` |
| 10 | +$ git clone http://josh/monorepo.git:/path/to/library.git |
| 11 | +``` |
| 12 | + |
| 13 | +The partial repo will act as a normal git repository but only contain the files |
| 14 | +found in the subdirectory and only commits affecting those files. |
| 15 | +The partial repo supports both fetch as well as push operation. |
| 16 | + |
| 17 | +This helps not just to improve performace on the client due to having fever files in |
| 18 | +the tree, |
| 19 | +it also enables collaboration on parts of the monorepo with other parties |
| 20 | +utilizing git's normal distributed development features. |
| 21 | +For example, this makes it easy to mirror just selected parts of your |
| 22 | +repo to public github repositories or specific customers. |
| 23 | + |
| 24 | +### Project composition / Workspaces |
| 25 | + |
| 26 | +Simplify code sharing and dependency management. Beyond just subdirectories, |
| 27 | +Josh supports filtering, re-mapping and composition of arbitrary virtual repositories |
| 28 | +from the content found in the monorepo. |
| 29 | + |
| 30 | +The mapping itself is also stored in the repository and therefore versioned alongside |
| 31 | +the code. |
| 32 | + |
| 33 | +Multiple projects, depending on a shared set of libraries, can thus live together in a single repository. |
7 | 34 | This approach is commonly referred to as “monorepo”, and was popularized by |
8 | 35 | [Google](https://people.engr.ncsu.edu/ermurph3/papers/seip18.pdf), Facebook or Twitter to name a |
9 | 36 | few. |
@@ -38,10 +65,65 @@ dependencies = :/modules:[ |
38 | 65 | </tbody> |
39 | 66 | </table> |
40 | 67 |
|
| 68 | +Workspaces act as normal git repos: |
| 69 | + |
| 70 | +``` |
| 71 | +$ git clone http://josh/central.git:workspace=workspaces/project1.git |
| 72 | +``` |
| 73 | + |
41 | 74 | Each of the subprojects defines a `workspace.josh` file, defining the mapping between the original central.git repository and the hierarchy in use inside of the project. |
42 | 75 |
|
43 | 76 | In this setup, project1 and project2 can seemlessly depend on the latest version of library1, while only checking out the part of the central monorepo that's needed for their purpose. |
44 | 77 | What's more, any changes to a shared module will be synced in both directions. |
45 | 78 |
|
46 | 79 | If a developper of the library1 pushed a new update, both projects will get the new version, and the developper will be able to check if they broke any test. |
47 | 80 | If a developper of project1 needs to update the library, the changes will be automatically shared back into central, and project2. |
| 81 | + |
| 82 | +### Simplified CI/CD |
| 83 | + |
| 84 | +With everything stored in one repo, CI/CD systems only need to look into one source for each particular |
| 85 | +deliverable. |
| 86 | +However in traditional monorepo environments dependency mangement is handled by the build system. |
| 87 | +Build systems are usually taylored to specific languages and need their input already checked |
| 88 | +out on the filesystem. |
| 89 | +So the question: |
| 90 | + |
| 91 | +> "What deliverables are affected by a given commit and need to be rebuild?" |
| 92 | +
|
| 93 | +cannot be answered without cloning the entire repository and understanding how the languages |
| 94 | +used handle dependencies. |
| 95 | + |
| 96 | +In particular when using C familiy languages, hidden dependencies on header files are easy to miss. |
| 97 | +For this reason limiting the visibility of files to the compiler by sandboxing is pretty much a requirement |
| 98 | +for reproducible builds. |
| 99 | + |
| 100 | +With Josh, each deliverable gets it's own virtual git repository with dependencies declared in the `workspace.josh` |
| 101 | +file. This means answering the above question becomes as simple as comparing commit ids. |
| 102 | +Furthermore due to the tree filtering each build is guaranteed to be perfectly sandboxed |
| 103 | +and only sees those parts of the monorepo that have actually been mapped. |
| 104 | + |
| 105 | +This also means the deliverables to be re-built can be determined without cloning any repos like |
| 106 | +typically necessary with normal build tools. |
| 107 | + |
| 108 | +### GraphQL API |
| 109 | + |
| 110 | +It is often desireable to access content stored in git without requiring a clone of the repository. |
| 111 | +This is usefull for CI/CD systems or web frontends such as dashboards. |
| 112 | + |
| 113 | +Josh exposes a GraphQL API for that purpose. For example, it can be used to find all workspaces currently |
| 114 | +present in the tree: |
| 115 | + |
| 116 | +``` |
| 117 | +query { |
| 118 | + rev(at:"refs/heads/master", filter:"::**/workspace.josh") { |
| 119 | + files { path } |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +### Caching proxy |
| 125 | + |
| 126 | +Even without using the more advanced features like partial cloning or workspaces, |
| 127 | +`josh-proxy` can act as a cache to reduce traffic between locations or keep your CI from |
| 128 | +performing many requests to the main git host. |
| 129 | + |
0 commit comments