Some teams of developer prefer to gather the source code of all the applications they are working on in a single repository instead of the traditional one repo per application. This code organization strategy is often called "mono repository" or "monorepo" in short. Deploying such applications requires some configuration. Follow our steps to deploy multiple applications from code hosted in a mono repository.
Imagine your project follows the monorepo pattern and has the following code structure:
my-app
├── api
├── front
├── admin
└── cockpit
It's easy to imagine that these applications form a homogeneous whole with a standardized communication method (synchronous HTTP calls, message queuing, etc.) between them.
Monorepos have several advantages:
In our example, a release is the release of the whole set of api, front, admin and cockpit applications and by setting up a robust Continuous Integration pipeline you can ensure that the 4 applications will work correctly together.
And by the way, Google uses monorepo.
With such a setup, you will need to create 4 applications on Scalingo: one for the API and 3 for the other applications. You can use the web dashboard or the CLI to do so.
In the "Code" section of each application on the web dashboard, enable the GitHub integration with your mono repository. You can activate the auto-deploy on one of the branch so that the application automatically get deployed when a commit is pushed on this branch. It's better if you choose the same branch for the 4 applications.
With the code of each application being in a different subfolder, you must teach Scalingo where to find the source code by defining the
PROJECT_DIR
environment variable of each application to match the corresponding folder. For
instance, the API application should have the following environment variable: PROJECT_DIR=api
.
If you've set up the GitHub integration and activate the Auto Deploy feature, you can also activate Review Apps. Review Apps are applications built dynamically every time a Pull Request is open against the connected GitHub repo. Of course this feature will work as well in the case of a monorepo!
For example, if the PR #42 is opened against our example monorepo, Scalingo will automatically build and deploy 4 Scalingo applications named api-42, front-42, admin-42 and cockpit-42 available behind their own scalingo.io domains. And they will follow the standard Review Apps workflow: when the PR is closed these 4 temporary applications will be destroyed by Scalingo.
If your code is not hosted on GitHub, the workflow is a bit more manual. We will configure Git to
send the code to different remote
. After creating the 4 apps on Scalingo, go to the root directory
of your project and add the 4 remotes with:
git remote set-url scalingo --push --add git@scalingo.com:api.git
git remote set-url scalingo --push --add git@scalingo.com:front.git
git remote set-url scalingo --push --add git@scalingo.com:admin.git
git remote set-url scalingo --push --add git@scalingo.com:cockpit.git
When you want to deploy a modification, just push to the scalingo
remote:
git push scalingo master
If you want to deploy a branch with a different name than master (e.g. prod
), replace master
in
the previous commands with prod:master
.
With this setup, you are now ready to be super efficient in the deployment of your applications. Just add a custom domain name and keep coding!
If you want to dig deeper the subject of monorepo you can begin to read this super awesome list of tools and readings.
Photo by Faye Cornish on Unsplash
At Scalingo (with our partners) we use trackers on our website.
Some of those are mandatory for the use of our website and can't be refused.
Some others are used to measure our audience as well as to improve our relationship with you or to send you quality content and advertising.