Azure 容器注册表 Webhook 参考Azure Container Registry webhook reference

可以为容器注册表配置 Webhook,以便对其执行某些操作时生成相应事件。You can configure webhooks for your container registry that generate events when certain actions are performed against it. 例如,启用将容器映像或 Helm 图表推送到注册表或者将其删除时要触发的 Webhook。For example, enable webhooks that are triggered when a container image or Helm chart is pushed to a registry, or deleted. 触发 Webhook 后,Azure 容器注册表向指定的终结点发出 HTTP 或 HTTPS 请求并包含有关此事件的信息。When a webhook is triggered, Azure Container Registry issues an HTTP or HTTPS request containing information about the event to an endpoint you specify. 然后终结点处理相应的 Webhook 和操作。Your endpoint can then process the webhook and act accordingly.

以下各部分详细介绍由受支持的事件生成的 Webhook 请求的架构。The following sections detail the schema of webhook requests generated by supported events. 事件部分包括事件类型的有效负载架构、示例请求有效负载以及触发 Webhook 的一个或多个示例命令。The event sections contain the payload schema for the event type, an example request payload, and one or more example commands that would trigger the webhook.

有关为 Azure 容器注册表配置 Webhook 的信息,请参阅使用 Azure 容器注册表 WebhookFor information about configuring webhooks for your Azure container registry, see Using Azure Container Registry webhooks.

Webhook 请求Webhook requests

HTTP 请求HTTP request

配置 Webhook 时,触发的 Webhook 向指定的 URL 终结点发出 HTTP POST 请求。A triggered webhook makes an HTTP POST request to the URL endpoint you specified when you configured the webhook.

HTTP 标头HTTP headers

如果尚未指定 Webhook 的 Content-Type 自定义标头,则 Webhook 请求包括 application/jsonContent-TypeWebhook requests include a Content-Type of application/json if you have not specified a Content-Type custom header for your webhook.

除为 Webhook 已指定的这些自定义标头外,不会向该请求添加任何其他标头。No other headers are added to the request beyond those custom headers you might have specified for the webhook.

Push 事件Push event

容器映像推送到存储库时触发的 Webhook。Webhook triggered when a container image is pushed to a repository.

Push 事件负载Push event payload

元素Element 类型Type 说明Description
id StringString Webhook 事件的 ID。The ID of the webhook event.
timestamp DateTimeDateTime 触发 Webhook 事件的时间。The time at which the webhook event was triggered.
action StringString 触发 Webhook 事件的操作。The action that triggered the webhook event.
目标target 复杂类型Complex Type 触发 Webhook 事件的事件目标。The target of the event that triggered the webhook event.
请求request 复杂类型Complex Type 生成 Webhook 事件的请求。The request that generated the webhook event.

目标target

元素Element 类型Type 说明Description
mediaType StringString 引用对象的 MIME 类型。The MIME type of the referenced object.
size Int32Int32 内容的字节数。The number of bytes of the content. 与 Length 字段相同。Same as Length field.
digest StringString 内容摘要,由注册表 V2 HTTP API 规范定义。The digest of the content, as defined by the Registry V2 HTTP API Specification.
length Int32Int32 内容的字节数。The number of bytes of the content. 与 Size 字段相同。Same as Size field.
repository StringString 存储库名称。The repository name.
tag StringString 映像标记名称。The image tag name.

请求request

元素Element 类型Type 说明Description
id StringString 启动事件的请求 ID。The ID of the request that initiated the event.
host StringString 注册表实例的外部可访问主机名,由传入请求中的 HTTP 主机标头指定。The externally accessible hostname of the registry instance, as specified by the HTTP host header on incoming requests.
method StringString 生成事件的请求方法。The request method that generated the event.
useragent StringString 请求的用户代理标头。The user agent header of the request.

有效负载示例:映像推送事件Payload example: image push event

{
  "id": "cb8c3971-9adc-488b-xxxx-43cbb4974ff5",
  "timestamp": "2017-11-17T16:52:01.343145347Z",
  "action": "push",
  "target": {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 524,
    "digest": "sha256:xxxxd5c8786bb9e621a45ece0dbxxxx1cdc624ad20da9fe62e9d25490f33xxxx",
    "length": 524,
    "repository": "hello-world",
    "tag": "v1"
  },
  "request": {
    "id": "3cbb6949-7549-4fa1-xxxx-a6d5451dffc7",
    "host": "myregistry.azurecr.cn",
    "method": "PUT",
    "useragent": "docker/17.09.0-ce go/go1.8.3 git-commit/afdb6d4 kernel/4.10.0-27-generic os/linux arch/amd64 UpstreamClient(Docker-Client/17.09.0-ce \\(linux\\))"
  }
}

触发映像推送事件 Webhook 的示例 Docker CLI 命令:Example Docker CLI command that triggers the image push event webhook:

docker push myregistry.azurecr.cn/hello-world:v1

图表推送事件Chart push event

将 Helm 图表推送到存储库时触发的 Webhook。Webhook triggered when a Helm chart is pushed to a repository.

图表推送事件有效负载Chart push event payload

元素Element 类型Type 说明Description
id StringString Webhook 事件的 ID。The ID of the webhook event.
timestamp DateTimeDateTime 触发 Webhook 事件的时间。The time at which the webhook event was triggered.
action StringString 触发 Webhook 事件的操作。The action that triggered the webhook event.
目标target 复杂类型Complex Type 触发 Webhook 事件的事件目标。The target of the event that triggered the webhook event.

目标target

元素Element 类型Type 说明Description
mediaType StringString 引用对象的 MIME 类型。The MIME type of the referenced object.
size Int32Int32 内容的字节数。The number of bytes of the content.
digest StringString 内容摘要,由注册表 V2 HTTP API 规范定义。The digest of the content, as defined by the Registry V2 HTTP API Specification.
repository StringString 存储库名称。The repository name.
tag StringString 图表标记名称。The chart tag name.
name StringString 图表名称。The chart name.
version StringString 图表版本。The chart version.

有效负载示例:图表推送事件Payload example: chart push event

{
  "id": "6356e9e0-627f-4fed-xxxx-d9059b5143ac",
  "timestamp": "2019-03-05T23:45:31.2614267Z",
  "action": "chart_push",
  "target": {
    "mediaType": "application/vnd.acr.helm.chart",
    "size": 25265,
    "digest": "sha256:xxxx8075264b5ba7c14c23672xxxx52ae6a3ebac1c47916e4efe19cd624dxxxx",
    "repository": "repo",
    "tag": "wordpress-5.4.0.tgz",
    "name": "wordpress",
    "version": "5.4.0.tgz"
  }
}

触发 chart_push 事件 Webhook 的示例 Azure CLI 命令:Example Azure CLI command that triggers the chart_push event webhook:

az acr helm push wordpress-5.4.0.tgz --name MyRegistry

删除活动Delete event

删除映像存储库或清单时触发的 Webhook。Webhook triggered when an image repository or manifest is deleted. 删除标记时不会触发 Webhook。Not triggered when a tag is deleted.

Delete 事件负载Delete event payload

元素Element 类型Type 说明Description
id StringString Webhook 事件的 ID。The ID of the webhook event.
timestamp DateTimeDateTime 触发 Webhook 事件的时间。The time at which the webhook event was triggered.
action StringString 触发 Webhook 事件的操作。The action that triggered the webhook event.
目标target 复杂类型Complex Type 触发 Webhook 事件的事件目标。The target of the event that triggered the webhook event.
请求request 复杂类型Complex Type 生成 Webhook 事件的请求。The request that generated the webhook event.

目标target

元素Element 类型Type 说明Description
mediaType StringString 引用对象的 MIME 类型。The MIME type of the referenced object.
digest StringString 内容摘要,由注册表 V2 HTTP API 规范定义。The digest of the content, as defined by the Registry V2 HTTP API Specification.
repository StringString 存储库名称。The repository name.

请求request

元素Element 类型Type 说明Description
id StringString 启动事件的请求 ID。The ID of the request that initiated the event.
host StringString 注册表实例的外部可访问主机名,由传入请求中的 HTTP 主机标头指定。The externally accessible hostname of the registry instance, as specified by the HTTP host header on incoming requests.
method StringString 生成事件的请求方法。The request method that generated the event.
useragent StringString 请求的用户代理标头。The user agent header of the request.

有效负载示例:映像删除事件Payload example: image delete event

{
    "id": "afc359ce-df7f-4e32-xxxx-1ff8aa80927b",
    "timestamp": "2017-11-17T16:54:53.657764628Z",
    "action": "delete",
    "target": {
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "digest": "sha256:xxxxd5c8786bb9e621a45ece0dbxxxx1cdc624ad20da9fe62e9d25490f33xxxx",
      "repository": "hello-world"
    },
    "request": {
      "id": "3d78b540-ab61-4f75-xxxx-7ca9ecf559b3",
      "host": "myregistry.azurecr.cn",
      "method": "DELETE",
      "useragent": "python-requests/2.18.4"
    }
  }

触发删除事件 Webhook 的示例 Azure CLI 命令:Example Azure CLI commands that trigger a delete event webhook:

# Delete repository
az acr repository delete --name MyRegistry --repository MyRepository

# Delete image
az acr repository delete --name MyRegistry --image MyRepository:MyTag

图表删除事件Chart delete event

删除 Helm 图表或存储库时触发的 Webhook。Webhook triggered when a Helm chart or repository is deleted.

图表删除事件有效负载Chart delete event payload

元素Element 类型Type 说明Description
id StringString Webhook 事件的 ID。The ID of the webhook event.
timestamp DateTimeDateTime 触发 Webhook 事件的时间。The time at which the webhook event was triggered.
action StringString 触发 Webhook 事件的操作。The action that triggered the webhook event.
目标target 复杂类型Complex Type 触发 Webhook 事件的事件目标。The target of the event that triggered the webhook event.

目标target

元素Element 类型Type 说明Description
mediaType StringString 引用对象的 MIME 类型。The MIME type of the referenced object.
size Int32Int32 内容的字节数。The number of bytes of the content.
digest StringString 内容摘要,由注册表 V2 HTTP API 规范定义。The digest of the content, as defined by the Registry V2 HTTP API Specification.
repository StringString 存储库名称。The repository name.
tag StringString 图表标记名称。The chart tag name.
name StringString 图表名称。The chart name.
version StringString 图表版本。The chart version.

有效负载示例:图表删除事件Payload example: chart delete event

{
  "id": "338a3ef7-ad68-4128-xxxx-fdd3af8e8f67",
  "timestamp": "2019-03-06T00:10:48.1270754Z",
  "action": "chart_delete",
  "target": {
    "mediaType": "application/vnd.acr.helm.chart",
    "size": 25265,
    "digest": "sha256:xxxx8075264b5ba7c14c23672xxxx52ae6a3ebac1c47916e4efe19cd624dxxxx",
    "repository": "repo",
    "tag": "wordpress-5.4.0.tgz",
    "name": "wordpress",
    "version": "5.4.0.tgz"
  }
}

触发 chart_delete 事件 Webhook 的示例 Azure CLI 命令:Example Azure CLI command that triggers the chart_delete event webhook:

az acr helm delete wordpress --version 5.4.0 --name MyRegistry

后续步骤Next steps

使用 Azure 容器注册表 webhookUsing Azure Container Registry webhooks