JFrog
在本示例中,您将在 JFrog 服务器和 Port 之间创建一个 webhook 集成,该集成将有助于将 JFrog 工件、Docker 标记和构建实体导入 Port。
Port 配置
创建以下蓝图定义:
Jfrog artifact blueprint
{
"identifier": "jfrogArtifact",
"description": "This blueprint represents an artifact in our JFrog catalog",
"title": "JFrog Artifact",
"icon": "JfrogXray",
"schema": {
"properties": {
"name": {
"type": "string",
"title": "Name",
"description": "Name of the artifact"
},
"path": {
"type": "string",
"title": "Path",
"description": "Path to artifact"
},
"sha256": {
"type": "string",
"title": "SHA 256",
"description": "SHA256 of the artifact"
},
"size": {
"type": "number",
"title": "Size",
"description": "Size of the artifact"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {
"repository": {
"title": "Repository",
"description": "Repository of the artifact",
"target": "jfrogRepository",
"required": false,
"many": false
}
}
}
Jfrog Docker tag blueprint
{
"identifier": "jfrogDockerTag",
"description": "This blueprint represents a Docker tag in our Jfrog catalog",
"title": "JFrog Docker Tag",
"icon": "JfrogXray",
"schema": {
"properties": {
"name": {
"type": "string",
"title": "Name",
"description": "Name of the Docker tag"
},
"imageName": {
"type": "string",
"title": "Image Name",
"description": "Name of the Docker image"
},
"path": {
"type": "string",
"title": "Path",
"description": "Path to Docker tag"
},
"sha256": {
"type": "string",
"title": "SHA 256",
"description": "SHA256 of the Docker tag"
},
"size": {
"type": "number",
"title": "Size",
"description": "Size of the Docker tag"
},
"tag": {
"type": "string",
"title": "Docker tag",
"description": "Docker tag"
},
"platforms": {
"type": "array",
"title": "Platforms",
"description": "Platforms supported by image"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {
"repository": {
"title": "Repository",
"description": "Repository of the artifact",
"target": "jfrogRepository",
"required": false,
"many": false
}
}
}
Jfrog repository blueprint
{
"identifier": "jfrogRepository",
"description": "This blueprint represents a repository on Jfrog",
"title": "JFrog Repository",
"icon": "JfrogXray",
"schema": {
"properties": {
"key": {
"type": "string",
"title": "Key",
"description": "Name of the repository"
},
"description": {
"type": "string",
"title": "Description",
"description": "Description of the repository"
},
"type": {
"type": "string",
"title": "Repository Type",
"description": "Type of the repository",
"enum": ["LOCAL", "REMOTE", "VIRTUAL", "FEDERATED", "DISTRIBUTION"],
"enumColors": {
"LOCAL": "blue",
"REMOTE": "bronze",
"VIRTUAL": "darkGray",
"FEDERATED": "green",
"DISTRIBUTION": "lightGray"
}
},
"url": {
"type": "string",
"title": "Repository URL",
"description": "URL to the repository",
"format": "url"
},
"packageType": {
"type": "string",
"title": "Package type",
"description": "Type of the package"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {}
}
Jfrog build blueprint
{
"identifier": "jfrogBuild",
"description": "This blueprint represents a build from JFrog",
"title": "JFrog Build",
"icon": "JfrogXray",
"schema": {
"properties": {
"name": {
"type": "string",
"title": "Build name",
"description": "Name of the build"
},
"uri": {
"type": "string",
"title": "Build URI",
"description": "URI to the build"
},
"lastStarted": {
"type": "string",
"title": "Last build time",
"description": "Last time the build ran",
"format": "date-time"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {}
}
Blueprint Properties
You may modify the properties in your blueprints depending on what you want to track in your JFrog repositories and builds.
创建以下 webhook 配置using Port's UI
JFrog webhook configuration
- 基本信息 选项卡 - 填写以下详细信息:
1.title:
JFrog mapper
; 2.标识符 :jfrogMapper
; 3.Description :将 JFrog 仓库和构建映射到 Port
的 webhook 配置; 4.图标 :JfrogXray
; - 集成配置选项卡 - 填写以下 JQ 映射:
[
{
"blueprint": "jfrogBuild",
"filter": ".body.event_type == 'uploaded'",
"entity": {
"identifier": ".body.build_name",
"title": ".body.build_name",
"properties": {
"name": ".body.build_name",
"uri": "'/' + .body.build_name",
"lastStarted": ".body.build_started"
}
}
},
{
"blueprint": "jfrogDockerTag",
"filter": ".body.event_type == 'pushed'",
"entity": {
"identifier": ".body.name",
"title": ".body.name",
"properties": {
"name": ".body.name",
"imageName": ".body.image_name",
"path": ".body.path",
"sha256": ".body.sha256",
"size": ".body.size",
"tag": ".body.tag",
"platforms": ".body.platforms[] | \"(.os):(.architecture)\""
},
"relations": {
"repository": ".body.repo_key"
}
}
},
{
"blueprint": "jfrogArtifact",
"filter": ".body.event_type == 'deployed'",
"entity": {
"identifier": ".body.data.name",
"title": ".body.data.name",
"properties": {
"name": ".body.data.name",
"path": ".body.data.path",
"sha256": ".body.data.sha256",
"size": ".body.data.size"
},
"relations": {
"repository": ".body.data.repo_key"
}
}
}
]
记下并复制该选项卡中提供的 Webhook URL
3.点击页面底部的保存。
在 JFrog 中创建 webhook
- 以具有管理员权限的用户身份登录 JFrog
- 点击用户图标左侧右上角的齿轮图标;
- 选择平台管理;
- 在左侧边栏底部,即常规下方,选择Webhooks;
- 点击创建 Webhook
- 输入以下详细信息:
- 名称"- 被用于一个有意义的名称,如Port-Artifact;
Description
- 输入 Webhook 的描述;URL
- 输入在 Port 中创建 webhook 配置后收到的url
键的值;Events
- 在Artifacts下,选择Artifact was deployed,然后选择所有相应的存储库; 7.单击页面底部的创建。 8.使用详细信息再创建两个 webhook: 1.用于构建:- 名称: Port-Build;
- 事件: 在构建下,选择构建已上传,然后选择所有适用的构建;
Description
- 输入 webhook 的描述;URL
- 输入您在 Port 中创建 webhook 配置后收到的url
键的值; 2.对于 Docker 标记:- 名称: Port-Docker-Tag;
- 事件: 在 Docker下,选择 Docker标签已推送,然后选择所有适用的软件源
为了查看 JFrog webhooks 中可用的不同有效载荷和事件、look here
完成!您发布、触发或上传的任何工件都将触发 Webhook 事件,JFrog 将把该事件发送到 Provider 提供的 Webhook URL。 Port 将根据映射解析事件并相应地更新目录实体。
让我们来测试一下
本节包括 JFrog 在上传构建时发送的 webhook 事件示例。 此外,本节还包括根据上一节提供的 webhook 配置从事件中创建的实体。
有效载荷
下面是上传 JFrob 构建时发送到 webhook URL 的有效载荷结构示例:
Webhook event payload
{
"build_name": "sample_build_name",
"event_type": "uploaded",
"build_number": "1",
"build_started": "2020-06-18T14:40:49.869+0300"
}
映射结果
{
"identifier": "sample_build_name",
"title": "sample_build_name",
"blueprint": "jfrogBuild",
"properties": {
"name": "sample_build_name",
"uri": "/sample_build_name",
"lastStarted": "21 hours ago"
},
"relations": {},
"filter": true
}