Monorepo Deployment
Monorepos are a common architectural pattern where multiple projects or components are stored within a single Git repository. Scalingo supports monorepos by allowing you to specify which subdirectory should be deployed for a given application.
The PROJECT_DIR Environment Variable
By default, Scalingo’s deployment system looks for the application’s entry point (e.g. package.json, Gemfile, requirements.txt) at the root of the Git repository.
In a monorepo setup, you need to tell Scalingo which directory contains the application you want to deploy. You can do this by setting the PROJECT_DIR environment variable.
How it Works
When PROJECT_DIR is set:
- The build system changes its working directory to the specified folder.
- Technology detection (buildpack selection) is performed within that directory.
- Only the content of this directory is included in the final application image.
Example Setup
Imagine a repository with the following structure:
.
├── backend/
│ ├── package.json
│ └── src/
├── frontend/
│ ├── package.json
│ └── src/
└── README.md
To deploy the backend and frontend as separate Scalingo applications from this single repository:
-
Create two applications on Scalingo (e.g.,
my-app-backendandmy-app-frontend). - Connect both applications to the same Git repository.
-
Configure the environment for each application:
- For
my-app-backend: SetPROJECT_DIR=backend - For
my-app-frontend: SetPROJECT_DIR=frontend
- For
The next time you push to the repository, each application will build and deploy only its respective subdirectory.
Common Use Cases
- Backend/Frontend Separation: Keeping your API and client-side code in the same repo but deploying them to different environments.
- Microservices: Managing multiple microservices in a single repository.
- Documentation: Keeping your documentation site alongside your application code.