The new project has come, and you need to reuse several libraries from the old one? Or maybe you have added a new microservice and need to reuse a couple of packages from other microservices?
In this report, I'm reviewing methods for reusing code between applications that we have experienced on our projects for several years. I show how to avoid copying the packages, while not spending additional resources on the publication of individual packages.
The talk is about practical usage of git submodules, composer public, private, VCS and "path" repositories, and git subtree splitter; benefits, and cons of each method, and how we used them in practice for multiple projects.
9. #2 Don’t reinvent the wheel
At ORO we don't.
● 190+ production dependencies
● 760+ dev & testing dependencies
10. #3 Many Repositories
● Every reusable package is a separate GIT repository
● Application repositories require package repositories
11. What to extract to the package?
We can declare every Symfony bundle as a new package.
12. What to extract to the package?
We can declare every Symfony bundle as a new package.
At ORO we have 170 + unique bundles
13. What to extract to the package?
Recommendations:
1. A single package has many related bundles
2. Start from big packages and extract when needed
3. Same root namespace for all the packages
16. # 3.1 Git Submodules
● Easy to start
● Hard to manage the code changes for a single task
17. # 3.2 Composer Packages
Each repo has its own composer.json
● Publish at Packagist.org
● Publish privately in Packagist.com or Satis
● Do not publish, but attach it as VCS repository
18. Pros:
● Versioning
● Simplified dependency management
Cons:
● Publishing is overhead
● Hard to manage the code changes for a single task
# 3.2 Composer Packages
20. What about storing all the projects in a single repo?
And delivering/deploying only what we need to.
21. #4 Monorepo
● All packages and applications are in a single repository
● Packages are not tight to a single technology
● Git Subtree allows to publish many repos from monorepo
27. ● Custom CLI command to switch active application in a monorepo
PHPStorm & Monorepo
28. Git Subtree & Monorepo
Automated split of the monorepo to many repositories
Pros:
● Saved history
● Supports two way sync
● Easy to add new repository
Cons:
● Requires CI integration
29. GitHub Code Owners & Monorepo
Define who is responsible for the code in .github/CODEOWNERS
30. Summary
No silver bullet
Solutions:
1. Copy & Paste
2. Don't write the code
3. Many repos
3.1. Git Submodules
3.2. Composer Packages
■ Public
■ Private
■ Unpublished
4. Monorepo