Container Registry API
Container Registry API
在 GitLab 11.8 中引入 .
这是GitLab 容器注册表的 API 文档.
List registry repositories
Within a project
获取项目中的注册表存储库列表.
GET /projects/:id/registry/repositories 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户可以访问的项目的 ID 或URL 编码路径 . | 
 tags  | 
boolean | no |  如果参数包含为 true,则每个存储库在响应中都将包含一个"tags"数组.  | 
 name  | 
string | no | 返回名称与值匹配的存储库列表. (在 GitLab 13.0 中引入 ). | 
 tags_count  | 
boolean | no |  如果参数包含为 true,则每个存储库的响应中都将包含"tags_count" (在 GitLab 13.1 中引入 ). | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories" 
响应示例:
[  {  "id":  1,  "name":  "",  "path":  "group/project",  "project_id":  9,  "location":  "gitlab.example.com:5000/group/project",  "created_at":  "2019-01-10T13:38:57.391Z"  },  {  "id":  2,  "name":  "releases",  "path":  "group/project/releases",  "project_id":  9,  "location":  "gitlab.example.com:5000/group/project/releases",  "created_at":  "2019-01-10T13:39:08.229Z"  }  ] 
Within a group
获取组中的注册表存储库列表.
GET /groups/:id/registry/repositories 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户可以访问的组的 ID 或URL 编码路径 . | 
 tags  | 
boolean | no |  如果参数包含为 true,则每个存储库在响应中都将包含一个"tags"数组.  | 
 name  | 
string | no | 返回名称与值匹配的存储库列表. (在 GitLab 13.0 中引入 ). | 
 tags_count  | 
boolean | no |  如果参数包含为 true,则每个存储库的响应中都将包含"tags_count" (在 GitLab 13.1 中引入 ). | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/2/registry/repositories?tags=1&tags_count=true" 
响应示例:
[  {  "id":  1,  "name":  "",  "path":  "group/project",  "project_id":  9,  "location":  "gitlab.example.com:5000/group/project",  "created_at":  "2019-01-10T13:38:57.391Z",  "tags_count":  1,  "tags":  [  {  "name":  "0.0.1",  "path":  "group/project:0.0.1",  "location":  "gitlab.example.com:5000/group/project:0.0.1"  }  ]  },  {  "id":  2,  "name":  "",  "path":  "group/other_project",  "project_id":  11,  "location":  "gitlab.example.com:5000/group/other_project",  "created_at":  "2019-01-10T13:39:08.229Z",  "tags_count":  3,  "tags":  [  {  "name":  "0.0.1",  "path":  "group/other_project:0.0.1",  "location":  "gitlab.example.com:5000/group/other_project:0.0.1"  },  {  "name":  "0.0.2",  "path":  "group/other_project:0.0.2",  "location":  "gitlab.example.com:5000/group/other_project:0.0.2"  },  {  "name":  "latest",  "path":  "group/other_project:latest",  "location":  "gitlab.example.com:5000/group/other_project:latest"  }  ]  }  ] 
Delete registry repository
删除注册表中的存储库.
该操作是异步执行的,可能要花一些时间才能执行.
DELETE /projects/:id/registry/repositories/:repository_id 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | The ID or URL-encoded path of the project owned by the authenticated user. | 
 repository_id  | 
integer | yes | 注册表存储库的标识. | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2" 
List registry repository tags
Within a project
获取给定注册表存储库的标签列表.
GET /projects/:id/registry/repositories/:repository_id/tags 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户可以访问的项目的 ID 或URL 编码路径 . | 
 repository_id  | 
integer | yes | 注册表存储库的标识. | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags" 
响应示例:
[  {  "name":  "A",  "path":  "group/project:A",  "location":  "gitlab.example.com:5000/group/project:A"  },  {  "name":  "latest",  "path":  "group/project:latest",  "location":  "gitlab.example.com:5000/group/project:latest"  }  ] 
Get details of a registry repository tag
获取注册表存储库标签的详细信息.
GET /projects/:id/registry/repositories/:repository_id/tags/:tag_name 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 经过身份验证的用户可以访问的项目的 ID 或URL 编码路径 . | 
 repository_id  | 
integer | yes | 注册表存储库的标识. | 
 tag_name  | 
string | yes | 标签名称. | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags/v10.0.0" 
响应示例:
{  "name":  "v10.0.0",  "path":  "group/project:latest",  "location":  "gitlab.example.com:5000/group/project:latest",  "revision":  "e9ed9d87c881d8c2fd3a31b41904d01ba0b836e7fd15240d774d811a1c248181",  "short_revision":  "e9ed9d87c",  "digest":  "sha256:c3490dcf10ffb6530c1303522a1405dfaf7daecd8f38d3e6a1ba19ea1f8a1751",  "created_at":  "2019-01-06T16:49:51.272+00:00",  "total_size":  350224384  } 
Delete a registry repository tag
删除注册表存储库标记.
DELETE /projects/:id/registry/repositories/:repository_id/tags/:tag_name 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 认证用户拥有的项目的 ID 或URL 编码路径 . | 
 repository_id  | 
integer | yes | 注册表存储库的标识. | 
 tag_name  | 
string | yes | 标签名称. | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags/v10.0.0" 
此操作不会删除 Blob. 为了删除它们并回收磁盘空间,请运行垃圾回收 .
Delete registry repository tags in bulk
根据给定的标准批量删除注册表存储库标签.
有关概述,请参阅利用 Container Registry API 删除除*之外的所有标签 .
DELETE /projects/:id/registry/repositories/:repository_id/tags 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer/string | yes | 认证用户拥有的项目的 ID 或URL 编码路径 . | 
 repository_id  | 
integer | yes | 注册表存储库的标识. | 
 name_regex  | 
string | no |  要删除的名称的re2正则表达式. 要删除所有标签,请指定.* . 注意:不建议使用name_regex而建议使用name_regex_delete . 此字段已验证.  | 
 name_regex_delete  | 
string | yes |  要删除的名称的re2正则表达式. 要删除所有标签,请指定.* . 此字段已验证.  | 
 name_regex_keep  | 
string | no |  要保留名称的re2正则表达式. 此值将覆盖name_regex_delete所有匹配name_regex_delete . 此字段已验证. 注意:设置为.*将导致无操作.  | 
 keep_n  | 
integer | no | 要保留的给定名称的最新标签的数量. | 
 older_than  | 
string | no |  早于给定时间的要删除的标签,以人类可读的格式1h , 1d , 1month编写. | 
此 API 调用执行以下操作:
- 它按创建日期排序所有标签. 创建日期是清单创建的时间,而不是标签推送的时间.
 - 它仅删除与给定
name_regex_delete(或不name_regex使用的name_regex)匹配的标签,并保留所有与name_regex_keep匹配的name_regex_keep. - 它绝不会取消对标签命名
latest. - 它保留 N 个最新的匹配标签(如果指定了
keep_n). - 它仅删除时间超过 X 时间的标签(如果指定了
older_than). - 它安排异步作业在后台执行.
 
这些操作是异步执行的,可能要花一些时间才能执行. 对于给定的容器存储库,您最多可以每小时运行一次. 此操作不会删除 Blob. 为了删除它们并回收磁盘空间,请运行垃圾回收 .
注意:从 GitLab 12.4 开始,将删除各个标签. 有关更多详细信息,请参见讨论 .
Examples:
删除与正则表达式(Git SHA)匹配的标记名,始终至少保留 5 个,并删除 2 天以上的标记名:
curl --request DELETE --data 'name_regex_delete=[0-9a-z]{40}' --data 'keep_n=5' --data 'older_than=2d' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags"- 删除所有标签,但始终保留最新的 5 个标签:
 
curl --request DELETE --data 'name_regex_delete=.*' --data 'keep_n=5' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags"- 删除所有标签,但始终保留以
stable开头的标签: 
curl --request DELETE --data 'name_regex_delete=.*' --data 'name_regex_keep=stable.*' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags"- 删除所有超过 1 个月的标签:
 
curl --request DELETE --data 'name_regex_delete=.*' --data 'older_than=1month' --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/registry/repositories/2/tags"