Dashboard CI/CD for mono-repos
A mono-repo keeps several services in one GitHub or Bitbucket repository, each with its own serverless.yml in its own directory, often next to a directory of shared code. Trigger directories in Serverless Dashboard CI/CD decide which commits deploy a service, so a commit deploys only the services whose files, or whose shared code, changed.
This page uses a repository with two services and one shared directory:
my-repo/
├── service1/
│ └── serverless.yml
├── service2/
│ └── serverless.yml
└── shared/
With trigger directories set as in Configure trigger directories, commits deploy these services:
| A commit changes files in | Deployed services |
|---|---|
service1/ | service1 |
service2/ | service2 |
shared/ | service1 and service2 |
Prerequisites
- Each service is connected to the repository in its Dashboard CI/CD settings, with its directory (
service1,service2) as the base directory and a branch deployment set up. Dashboard CI/CD shows how. - The
servicevalue in each directory'sserverless.ymlmatches the Dashboard service you configure.
Configure trigger directories
Trigger directories are set per service, in the Trigger Directories section of the service's CI/CD settings. For service1:
- Open the CI/CD settings of
service1in the Dashboard. - In Trigger Directories, clear Always trigger a deployment. The service's base directory,
service1, is added as a trigger directory. - Add
./sharedas a trigger directory.
Repeat the steps for service2. Its base directory, service2, is added in step 2.
To verify the setup, push a commit that changes only a file in service2/ to a branch with a branch deployment. The Deployments view in the Dashboard lists a new deployment for service2 and none for service1.
How trigger directories select deployments
The Always trigger a deployment option in a service's Trigger Directories settings decides how commits start deployments of that service:
- Selected (the default): every commit to a branch the service deploys from starts a deployment, whichever files the commit changed. In a mono-repo, every service redeploys on every commit.
- Cleared: a commit starts a deployment only when it changes at least one file inside one of the service's trigger directories. A commit that changes files only in other directories doesn't deploy the service.
Trigger directories only decide whether a commit starts a deployment. The deployment itself runs the service from its base directory.
Related pages
- Dashboard CI/CD: connect a repository and choose a base directory.
- Branch deployments: map branches to stages.
- Dashboard CI/CD best practices: organize services, accounts and secrets.