Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
26968b70
提交
26968b70
编辑于
4 years ago
作者:
Steve Abrams
提交者:
Sean McGivern
4 years ago
浏览文件
操作
下载
补丁
差异文件
Detect container registry vendor/version/features
Co-authored-by:
João Pereira
<
jpereira@gitlab.com
>
上级
f35bf8cb
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
lib/container_registry/client.rb
+17
-0
17 个添加, 0 个删除
lib/container_registry/client.rb
spec/lib/container_registry/client_spec.rb
+51
-1
51 个添加, 1 个删除
spec/lib/container_registry/client_spec.rb
有
68 个添加
和
1 个删除
lib/container_registry/client.rb
+
17
−
0
浏览文件 @
26968b70
...
...
@@ -13,6 +13,8 @@ class Client
DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE
=
'application/vnd.docker.distribution.manifest.v2+json'
OCI_MANIFEST_V1_TYPE
=
'application/vnd.oci.image.manifest.v1+json'
CONTAINER_IMAGE_V1_TYPE
=
'application/vnd.docker.container.image.v1+json'
REGISTRY_VERSION_HEADER
=
'gitlab-container-registry-version'
REGISTRY_FEATURES_HEADER
=
'gitlab-container-registry-features'
ACCEPTED_TYPES
=
[
DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE
,
OCI_MANIFEST_V1_TYPE
].
freeze
...
...
@@ -24,6 +26,21 @@ def initialize(base_uri, options = {})
@options
=
options
end
def
registry_info
response
=
faraday
.
get
(
"/v2/"
)
return
{}
unless
response
&
.
success?
version
=
response
.
headers
[
REGISTRY_VERSION_HEADER
]
features
=
response
.
headers
.
fetch
(
REGISTRY_FEATURES_HEADER
,
''
)
{
version:
version
,
features:
features
.
split
(
','
).
map
(
&
:strip
),
vendor:
version
?
'gitlab'
:
'other'
}
end
def
repository_tags
(
name
)
response_body
faraday
.
get
(
"/v2/
#{
name
}
/tags/list"
)
end
...
...
此差异已折叠。
点击以展开。
spec/lib/container_registry/client_spec.rb
+
51
−
1
浏览文件 @
26968b70
...
...
@@ -85,7 +85,7 @@
it
'follows 307 redirect for GET /v2/:name/blobs/:digest'
do
stub_request
(
:get
,
"http://container-registry/v2/group/test/blobs/sha256:0123456789012345"
)
.
with
(
headers:
blob_headers
)
.
to_return
(
status:
307
,
body:
""
,
headers:
{
Location
:
'http://redirected'
})
.
to_return
(
status:
307
,
body:
''
,
headers:
{
Location
:
'http://redirected'
})
# We should probably use hash_excluding here, but that requires an update to WebMock:
# https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb
stub_request
(
:get
,
"http://redirected/"
)
...
...
@@ -238,4 +238,54 @@ def stub_upload(path, content, digest, status = 200)
it
{
is_expected
.
to
be_falsey
}
end
end
def
stub_registry_info
(
headers:
{},
status:
200
)
stub_request
(
:get
,
'http://container-registry/v2/'
)
.
to_return
(
status:
status
,
body:
""
,
headers:
headers
)
end
describe
'#registry_info'
do
subject
{
client
.
registry_info
}
context
'when the check is successful'
do
context
'when using the GitLab container registry'
do
before
do
stub_registry_info
(
headers:
{
'GitLab-Container-Registry-Version'
=>
'2.9.1-gitlab'
,
'GitLab-Container-Registry-Features'
=>
'a,b,c'
})
end
it
'identifies the vendor as "gitlab"'
do
expect
(
subject
).
to
include
(
vendor:
'gitlab'
)
end
it
'identifies version and features'
do
expect
(
subject
).
to
include
(
version:
'2.9.1-gitlab'
,
features:
%w[a b c]
)
end
end
context
'when using a third-party container registry'
do
before
do
stub_registry_info
end
it
'identifies the vendor as "other"'
do
expect
(
subject
).
to
include
(
vendor:
'other'
)
end
it
'does not identify version or features'
do
expect
(
subject
).
to
include
(
version:
nil
,
features:
[])
end
end
end
context
'when the check is not successful'
do
it
'does not identify vendor, version or features'
do
stub_registry_info
(
status:
500
)
expect
(
subject
).
to
eq
({})
end
end
end
end
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录