Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
af42dd29
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
af42dd29
编写于
3月 24, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix specs for container repository tags
上级
dcd2eeb1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
35 deletion
+64
-35
app/models/container_repository.rb
app/models/container_repository.rb
+5
-3
lib/container_registry/blob.rb
lib/container_registry/blob.rb
+2
-2
lib/container_registry/tag.rb
lib/container_registry/tag.rb
+3
-3
spec/factories/container_repositories.rb
spec/factories/container_repositories.rb
+11
-12
spec/lib/container_registry/tag_spec.rb
spec/lib/container_registry/tag_spec.rb
+43
-15
未找到文件。
app/models/container_repository.rb
浏览文件 @
af42dd29
class
ContainerRepository
<
ActiveRecord
::
Base
class
ContainerRepository
<
ActiveRecord
::
Base
belongs_to
:project
belongs_to
:project
delegate
:client
,
to: :registry
validates
:manifest
,
presence:
true
validates
:manifest
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
length:
{
minimum:
0
,
allow_nil:
false
}
delegate
:client
,
to: :registry
before_destroy
:delete_tags
before_destroy
:delete_tags
def
registry
def
registry
...
@@ -17,7 +19,7 @@ class ContainerRepository < ActiveRecord::Base
...
@@ -17,7 +19,7 @@ class ContainerRepository < ActiveRecord::Base
end
end
def
path
def
path
@path
||=
"
#{
project
.
full_path
}
/
#{
name
}
"
@path
||=
[
project
.
full_path
,
name
].
select
(
&
:present?
).
join
(
'/'
)
end
end
def
tag
(
tag
)
def
tag
(
tag
)
...
...
lib/container_registry/blob.rb
浏览文件 @
af42dd29
...
@@ -38,11 +38,11 @@ module ContainerRegistry
...
@@ -38,11 +38,11 @@ module ContainerRegistry
end
end
def
delete
def
delete
client
.
delete_blob
(
repository
.
name_with_namespace
,
digest
)
client
.
delete_blob
(
repository
.
path
,
digest
)
end
end
def
data
def
data
@data
||=
client
.
blob
(
repository
.
name_with_namespace
,
digest
,
type
)
@data
||=
client
.
blob
(
repository
.
path
,
digest
,
type
)
end
end
end
end
end
end
lib/container_registry/tag.rb
浏览文件 @
af42dd29
...
@@ -22,7 +22,7 @@ module ContainerRegistry
...
@@ -22,7 +22,7 @@ module ContainerRegistry
end
end
def
manifest
def
manifest
@manifest
||=
client
.
repository_manifest
(
repository
.
name_with_namespace
,
name
)
@manifest
||=
client
.
repository_manifest
(
repository
.
path
,
name
)
end
end
def
path
def
path
...
@@ -38,7 +38,7 @@ module ContainerRegistry
...
@@ -38,7 +38,7 @@ module ContainerRegistry
def
digest
def
digest
return
@digest
if
defined?
(
@digest
)
return
@digest
if
defined?
(
@digest
)
@digest
=
client
.
repository_tag_digest
(
repository
.
name_with_namespace
,
name
)
@digest
=
client
.
repository_tag_digest
(
repository
.
path
,
name
)
end
end
def
config_blob
def
config_blob
...
@@ -80,7 +80,7 @@ module ContainerRegistry
...
@@ -80,7 +80,7 @@ module ContainerRegistry
def
delete
def
delete
return
unless
digest
return
unless
digest
client
.
delete_repository_tag
(
repository
.
name_with_namespace
,
digest
)
client
.
delete_repository_tag
(
repository
.
path
,
digest
)
end
end
end
end
end
end
spec/factories/container_repositories.rb
浏览文件 @
af42dd29
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:container_repository
do
factory
:container_repository
do
name
"test_container_image"
name
'test_container_image'
project
project
transient
do
transient
do
tags
[
'tag'
]
tags
[]
end
end
after
(
:build
)
do
|
image
,
evaluator
|
after
(
:build
)
do
|
repository
,
evaluator
|
# if evaluator.tags.to_a.any?
if
evaluator
.
tags
.
any?
# allow(Gitlab.config.registry).to receive(:enabled).and_return(true)
allow
(
repository
.
client
)
# allow(Auth::ContainerRegistryAuthenticationService)
.
to
receive
(
:repository_tags
)
# .to receive(:full_access_token).and_return('token')
.
and_return
({
# allow(image.client).to receive(:repository_tags).and_return({
name:
repository
.
path
,
# name: image.name_with_namespace,
tags:
evaluator
.
tags
# tags: evaluator.tags
})
# })
end
# end
end
end
end
end
end
end
spec/lib/container_registry/tag_spec.rb
浏览文件 @
af42dd29
...
@@ -3,30 +3,58 @@ require 'spec_helper'
...
@@ -3,30 +3,58 @@ require 'spec_helper'
describe
ContainerRegistry
::
Tag
do
describe
ContainerRegistry
::
Tag
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
group:
group
)
}
let
(
:example_host
)
{
'example.com'
}
let
(
:registry_url
)
{
'http://'
+
example_host
}
let
(
:repository
)
do
let
(
:repository
)
{
create
(
:container_repository
,
name:
''
,
project:
project
)
}
create
(
:container_repository
,
name:
''
,
tags:
%w[latest]
,
project:
project
)
let
(
:tag
)
{
repository
.
tag
(
'tag'
)
}
end
let
(
:headers
)
{
{
'Accept'
=>
'application/vnd.docker.distribution.manifest.v2+json'
}
}
# TODO, move stubs to helper with this header
let
(
:headers
)
do
{
'Accept'
=>
'application/vnd.docker.distribution.manifest.v2+json'
}
end
let
(
:tag
)
{
described_class
.
new
(
repository
,
'tag'
)
}
before
do
before
do
stub_container_registry_config
(
enabled:
true
,
api_url:
registry_url
,
host_port:
example_host
)
stub_container_registry_config
(
enabled:
true
,
api_url:
'http://registry.gitlab'
,
host_port:
'registry.gitlab'
)
end
end
it
{
expect
(
tag
).
to
respond_to
(
:repository
)
}
it
{
expect
(
tag
).
to
respond_to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:registry
).
to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:registry
).
to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:client
).
to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:client
).
to
(
:repository
)
}
context
'#path'
do
describe
'#path'
do
subject
{
tag
.
path
}
context
'when tag belongs to zero-level repository'
do
let
(
:repository
)
do
create
(
:container_repository
,
name:
''
,
tags:
%w[rc1]
,
project:
project
)
end
it
{
is_expected
.
to
eq
(
'example.com/group/test:tag'
)
}
it
'returns path to the image'
do
expect
(
tag
.
path
).
to
eq
(
'group/test:tag'
)
end
end
context
'when tag belongs to first-level repository'
do
let
(
:repository
)
do
create
(
:container_repository
,
name:
'my_image'
,
tags:
%w[latest]
,
project:
project
)
end
it
'returns path to the image'
do
expect
(
tag
.
path
).
to
eq
(
'group/test/my_image:tag'
)
end
end
end
end
context
'manifest processing'
do
context
'manifest processing'
do
context
'schema v1'
do
context
'schema v1'
do
before
do
before
do
stub_request
(
:get
,
'http://
example.com
/v2/group/test/manifests/tag'
).
stub_request
(
:get
,
'http://
registry.gitlab
/v2/group/test/manifests/tag'
).
with
(
headers:
headers
).
with
(
headers:
headers
).
to_return
(
to_return
(
status:
200
,
status:
200
,
...
@@ -63,7 +91,7 @@ describe ContainerRegistry::Tag do
...
@@ -63,7 +91,7 @@ describe ContainerRegistry::Tag do
context
'schema v2'
do
context
'schema v2'
do
before
do
before
do
stub_request
(
:get
,
'http://
example.com
/v2/group/test/manifests/tag'
).
stub_request
(
:get
,
'http://
registry.gitlab
/v2/group/test/manifests/tag'
).
with
(
headers:
headers
).
with
(
headers:
headers
).
to_return
(
to_return
(
status:
200
,
status:
200
,
...
@@ -100,7 +128,7 @@ describe ContainerRegistry::Tag do
...
@@ -100,7 +128,7 @@ describe ContainerRegistry::Tag do
context
'when locally stored'
do
context
'when locally stored'
do
before
do
before
do
stub_request
(
:get
,
'http://
example.com
/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'
).
stub_request
(
:get
,
'http://
registry.gitlab
/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'
).
with
(
headers:
{
'Accept'
=>
'application/octet-stream'
}).
with
(
headers:
{
'Accept'
=>
'application/octet-stream'
}).
to_return
(
to_return
(
status:
200
,
status:
200
,
...
@@ -112,7 +140,7 @@ describe ContainerRegistry::Tag do
...
@@ -112,7 +140,7 @@ describe ContainerRegistry::Tag do
context
'when externally stored'
do
context
'when externally stored'
do
before
do
before
do
stub_request
(
:get
,
'http://
example.com
/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'
).
stub_request
(
:get
,
'http://
registry.gitlab
/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac'
).
with
(
headers:
{
'Accept'
=>
'application/octet-stream'
}).
with
(
headers:
{
'Accept'
=>
'application/octet-stream'
}).
to_return
(
to_return
(
status:
307
,
status:
307
,
...
@@ -132,7 +160,7 @@ describe ContainerRegistry::Tag do
...
@@ -132,7 +160,7 @@ describe ContainerRegistry::Tag do
context
'manifest digest'
do
context
'manifest digest'
do
before
do
before
do
stub_request
(
:head
,
'http://
example.com
/v2/group/test/manifests/tag'
).
stub_request
(
:head
,
'http://
registry.gitlab
/v2/group/test/manifests/tag'
).
with
(
headers:
headers
).
with
(
headers:
headers
).
to_return
(
status:
200
,
headers:
{
'Docker-Content-Digest'
=>
'sha256:digest'
})
to_return
(
status:
200
,
headers:
{
'Docker-Content-Digest'
=>
'sha256:digest'
})
end
end
...
@@ -145,7 +173,7 @@ describe ContainerRegistry::Tag do
...
@@ -145,7 +173,7 @@ describe ContainerRegistry::Tag do
context
'#delete'
do
context
'#delete'
do
before
do
before
do
stub_request
(
:delete
,
'http://
example.com
/v2/group/test/manifests/sha256:digest'
).
stub_request
(
:delete
,
'http://
registry.gitlab
/v2/group/test/manifests/sha256:digest'
).
with
(
headers:
headers
).
with
(
headers:
headers
).
to_return
(
status:
200
)
to_return
(
status:
200
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录