Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
af42dd29
Commit
af42dd29
authored
Mar 24, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs for container repository tags
parent
dcd2eeb1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
35 deletions
+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
No files found.
app/models/container_repository.rb
View file @
af42dd29
class
ContainerRepository
<
ActiveRecord
::
Base
belongs_to
:project
delegate
:client
,
to: :registry
validates
:manifest
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
length:
{
minimum:
0
,
allow_nil:
false
}
delegate
:client
,
to: :registry
before_destroy
:delete_tags
def
registry
...
...
@@ -17,7 +19,7 @@ class ContainerRepository < ActiveRecord::Base
end
def
path
@path
||=
"
#{
project
.
full_path
}
/
#{
name
}
"
@path
||=
[
project
.
full_path
,
name
].
select
(
&
:present?
).
join
(
'/'
)
end
def
tag
(
tag
)
...
...
lib/container_registry/blob.rb
View file @
af42dd29
...
...
@@ -38,11 +38,11 @@ module ContainerRegistry
end
def
delete
client
.
delete_blob
(
repository
.
name_with_namespace
,
digest
)
client
.
delete_blob
(
repository
.
path
,
digest
)
end
def
data
@data
||=
client
.
blob
(
repository
.
name_with_namespace
,
digest
,
type
)
@data
||=
client
.
blob
(
repository
.
path
,
digest
,
type
)
end
end
end
lib/container_registry/tag.rb
View file @
af42dd29
...
...
@@ -22,7 +22,7 @@ module ContainerRegistry
end
def
manifest
@manifest
||=
client
.
repository_manifest
(
repository
.
name_with_namespace
,
name
)
@manifest
||=
client
.
repository_manifest
(
repository
.
path
,
name
)
end
def
path
...
...
@@ -38,7 +38,7 @@ module ContainerRegistry
def
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
def
config_blob
...
...
@@ -80,7 +80,7 @@ module ContainerRegistry
def
delete
return
unless
digest
client
.
delete_repository_tag
(
repository
.
name_with_namespace
,
digest
)
client
.
delete_repository_tag
(
repository
.
path
,
digest
)
end
end
end
spec/factories/container_repositories.rb
View file @
af42dd29
FactoryGirl
.
define
do
factory
:container_repository
do
name
"test_container_image"
name
'test_container_image'
project
transient
do
tags
[
'tag'
]
tags
[]
end
after
(
:build
)
do
|
image
,
evaluator
|
# if evaluator.tags.to_a.any?
# allow(Gitlab.config.registry).to receive(:enabled).and_return(true)
# allow(Auth::ContainerRegistryAuthenticationService)
# .to receive(:full_access_token).and_return('token')
# allow(image.client).to receive(:repository_tags).and_return({
# name: image.name_with_namespace,
# tags: evaluator.tags
# })
# end
after
(
:build
)
do
|
repository
,
evaluator
|
if
evaluator
.
tags
.
any?
allow
(
repository
.
client
)
.
to
receive
(
:repository_tags
)
.
and_return
({
name:
repository
.
path
,
tags:
evaluator
.
tags
})
end
end
end
end
spec/lib/container_registry/tag_spec.rb
View file @
af42dd29
...
...
@@ -3,30 +3,58 @@ require 'spec_helper'
describe
ContainerRegistry
::
Tag
do
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
group:
group
)
}
let
(
:example_host
)
{
'example.com'
}
let
(
:registry_url
)
{
'http://'
+
example_host
}
let
(
:repository
)
{
create
(
:container_repository
,
name:
''
,
project:
project
)
}
let
(
:tag
)
{
repository
.
tag
(
'tag'
)
}
let
(
:headers
)
{
{
'Accept'
=>
'application/vnd.docker.distribution.manifest.v2+json'
}
}
let
(
:repository
)
do
create
(
:container_repository
,
name:
''
,
tags:
%w[latest]
,
project:
project
)
end
# 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
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
it
{
expect
(
tag
).
to
respond_to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:registry
).
to
(
:repository
)
}
it
{
expect
(
tag
).
to
delegate_method
(
:client
).
to
(
:repository
)
}
context
'#path'
do
subject
{
tag
.
path
}
describe
'#path'
do
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
context
'manifest processing'
do
context
'schema v1'
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
).
to_return
(
status:
200
,
...
...
@@ -63,7 +91,7 @@ describe ContainerRegistry::Tag do
context
'schema v2'
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
).
to_return
(
status:
200
,
...
...
@@ -100,7 +128,7 @@ describe ContainerRegistry::Tag do
context
'when locally stored'
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'
}).
to_return
(
status:
200
,
...
...
@@ -112,7 +140,7 @@ describe ContainerRegistry::Tag do
context
'when externally stored'
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'
}).
to_return
(
status:
307
,
...
...
@@ -132,7 +160,7 @@ describe ContainerRegistry::Tag do
context
'manifest digest'
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
).
to_return
(
status:
200
,
headers:
{
'Docker-Content-Digest'
=>
'sha256:digest'
})
end
...
...
@@ -145,7 +173,7 @@ describe ContainerRegistry::Tag do
context
'#delete'
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
).
to_return
(
status:
200
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment