Python
In this example you are going to create a package blueprint that ingests all third party dependencies and libraries in your requirements.txt file using a combination of Port's API and webhook functionality. You will then relate this blueprint to a service blueprint, allowing you to map all the packages used by a service.
To ingest the packages to Port, a script that sends information about packages according to the webhook configuration is used.
Prerequisites
Create the following blueprint definition and webhook configuration:
Service blueprint
{
"identifier": "service",
"title": "Service",
"icon": "Service",
"schema": {
"properties": {
"description": {
"title": "Description",
"type": "string"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
Package blueprint
{
"identifier": "packages",
"description": "This blueprint represents a software package file in our catalog",
"title": "Package",
"icon": "Package",
"schema": {
"properties": {
"version": {
"type": "string",
"title": "Depedency Version"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"service": {
"title": "Service",
"target": "service",
"required": false,
"many": true
}
}
}
Package webhook configuration
{
"identifier": "packagesMapper",
"title": "Package Mapper",
"description": "A webhook configuration to map packages and dependencies from a file",
"icon": "Package",
"mappings": [
{
"blueprint": "packages",
"itemsToParse": ".body.dependencies",
"entity": {
"identifier": ".item.id",
"title": ".item.name",
"properties": {
"version": ".item.version"
},
"relations": {
"service": ".body.service"
}
}
}
],
"enabled": true,
"security": {}
}
Working with Port's API and Bash script
Here is an example snippet showing how to integrate Port's API and Webhook with your existing pipelines using Python and Bash:
- Python
- Bash
Create the following Python script in your repository to create or update Port entities as part of your pipeline: Python script example
Create the following Bash script in your repository to create or update Port entities as part of your pipeline: Bash script example
For an example showing how to integrate the above scripts with your existing Gitlab CI pipelines, visit: