Working with monorepos
After connecting your Git provider to Port, Port will automatically create an entity💡 Port Concepts
Entity - An instance of a blueprint, represents data as defined by that blueprint's properties. Learn more for each repository in the organization in which you installed the integration.
If you're working with a monorepo and would like to create an entity for each microservice in a single repository instead, you can do that by making an adjustment to your Git integration's mapping:
- Go to the connectors page in the Port app.
- Under
Exporters, click on the Git provider you would like to edit, for example:
- A window will open with a YAML mapping of the integration.
Use the following snippet as needed for your use-case (either add thefolderentry to theresourcesarray, or replace the entire YAML with it):
In the snippet below, change the path and repos fields to your desired values before copying.
- GitHub
- GitLab
- BitBucket
- Azure DevOps (coming soon)
If you want to ingest a README.md for each folder (for example apps/service-a/README.md), use Option A below.
If you want to ingest the repository's root README.md and attach it to every folder entity, use Option B.
Option A — folder README (resolved relative to each matched folder path):
resources:
- kind: folder
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
folders: # Specify the repositories and folders to include under this relative path.
- path: apps/* # Relative path to the folders within the repositories.
includedFiles:
# For GitHub folder entities, includedFiles declared here are resolved per folder
# (e.g. apps/service-a/README.md) and attached under .folder.__includedFiles
- README.md
repos: # List of repositories to include folders from.
- backend-service
- frontend-service
port:
entity:
mappings:
identifier: ".folder.name"
title: ".folder.name"
blueprint: '"githubRepository"'
properties:
url: .repo.html_url + "/tree/" + .repo.default_branch + "/" + .folder.path
readme: .folder.__includedFiles["README.md"]
Option B — repository root README (same README for all folders):
resources:
- kind: folder
selector:
query: "true"
folders:
- path: apps/*
repos:
- backend-service
- frontend-service
includedFiles:
# These paths are fetched from the repository root and attached under .__includedFiles
- README.md
port:
entity:
mappings:
identifier: ".folder.name"
title: ".folder.name"
blueprint: '"githubRepository"'
properties:
url: .repo.html_url + "/tree/" + .repo.default_branch + "/" + .folder.path
readme: .__includedFiles["README.md"]
resources:
- kind: folder
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
folders: # Specify the repositories and folders to include under this relative path.
- path: "apps/" # Relative path to the folders within the repositories.
repos: # List of repositories to include folders from (use path_with_namespace).
- group/backend-service
- group/frontend-service
includedFiles:
- README.md
port:
entity:
mappings:
identifier: .folder.name
title: .folder.name
blueprint: '"service"'
properties:
url: >-
.repo.web_url + "/tree/" + .repo.default_branch + "/" +
.folder.path
language: .repo.__languages | to_entries | max_by(.value) | .key
readme: .__includedFiles["README.md"]
resources:
- kind: folder
selector:
query: "true" # JQ boolean query. If evaluated to false - skip syncing the object.
folders: # Specify the repositories and folders to include under this relative path.
- path: apps/* # Relative path to the folders within the repositories.
repos: # List of repositories to include folders from.
- backend-service
- frontend-service
includedFiles:
- README.md
port:
entity:
mappings:
identifier: .folder.name
blueprint: '"bitbucketRepository"'
properties:
url: .repo.links.html.href + "/src/" + .repo.mainbranch.name + "/" + .folder.path
readme: .__includedFiles["README.md"]
Currently monorepo support is available for the Git providers listed below.
Support for Azure DevOps is coming soon. Stay tuned!
-
Click on
Resyncto apply the changes. -
Head back to your Catalog, as you can see Port has now created an entity for each folder in the specified repositories, instead of creating an entity for each repository.