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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
d05f0030
Commit
d05f0030
authored
May 09, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Docker Registry View tests
parent
d5d8e76b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
87 additions
and
27 deletions
+87
-27
app/controllers/jwt_controller.rb
app/controllers/jwt_controller.rb
+1
-1
app/services/jwt/container_registry_authentication_service.rb
...services/jwt/container_registry_authentication_service.rb
+4
-2
app/services/projects/destroy_service.rb
app/services/projects/destroy_service.rb
+1
-1
app/views/projects/container_registry/_tag.html.haml
app/views/projects/container_registry/_tag.html.haml
+20
-0
app/views/projects/container_registry/index.html.haml
app/views/projects/container_registry/index.html.haml
+2
-21
lib/container_registry/client.rb
lib/container_registry/client.rb
+2
-2
spec/features/container_registry_spec.rb
spec/features/container_registry_spec.rb
+43
-0
spec/fixtures/container_registry/config_blob.json
spec/fixtures/container_registry/config_blob.json
+1
-0
spec/fixtures/container_registry/tag_manifest.json
spec/fixtures/container_registry/tag_manifest.json
+1
-0
spec/support/stub_gitlab_calls.rb
spec/support/stub_gitlab_calls.rb
+12
-0
No files found.
app/controllers/jwt_controller.rb
View file @
d05f0030
...
@@ -3,7 +3,7 @@ class JwtController < ApplicationController
...
@@ -3,7 +3,7 @@ class JwtController < ApplicationController
skip_before_action
:verify_authenticity_token
skip_before_action
:verify_authenticity_token
SERVICES
=
{
SERVICES
=
{
'container_registry'
=>
Jwt
::
ContainerRegistryAuthenticationService
,
Jwt
::
ContainerRegistryAuthenticationService
::
AUDIENCE
=>
Jwt
::
ContainerRegistryAuthenticationService
,
}
}
def
auth
def
auth
...
...
app/services/jwt/container_registry_authentication_service.rb
View file @
d05f0030
module
Jwt
module
Jwt
class
ContainerRegistryAuthenticationService
<
BaseService
class
ContainerRegistryAuthenticationService
<
BaseService
AUDIENCE
=
'container_registry'
def
execute
def
execute
if
params
[
:offline_token
]
if
params
[
:offline_token
]
return
error
(
'forbidden'
,
403
)
unless
current_user
return
error
(
'forbidden'
,
403
)
unless
current_user
...
@@ -14,7 +16,7 @@ module Jwt
...
@@ -14,7 +16,7 @@ module Jwt
registry
=
Gitlab
.
config
.
registry
registry
=
Gitlab
.
config
.
registry
token
=
::
Jwt
::
RSAToken
.
new
(
registry
.
key
)
token
=
::
Jwt
::
RSAToken
.
new
(
registry
.
key
)
token
.
issuer
=
registry
.
issuer
token
.
issuer
=
registry
.
issuer
token
.
audience
=
'docker'
token
.
audience
=
AUDIENCE
token
[
:access
]
=
names
.
map
do
|
name
|
token
[
:access
]
=
names
.
map
do
|
name
|
{
type:
'repository'
,
name:
name
,
actions:
%w(pull push)
}
{
type:
'repository'
,
name:
name
,
actions:
%w(pull push)
}
end
end
...
@@ -26,7 +28,7 @@ module Jwt
...
@@ -26,7 +28,7 @@ module Jwt
def
authorized_token
(
access
)
def
authorized_token
(
access
)
token
=
::
Jwt
::
RSAToken
.
new
(
registry
.
key
)
token
=
::
Jwt
::
RSAToken
.
new
(
registry
.
key
)
token
.
issuer
=
registry
.
issuer
token
.
issuer
=
registry
.
issuer
token
.
audience
=
params
[
:service
]
token
.
audience
=
AUDIENCE
token
.
subject
=
current_user
.
try
(
:username
)
token
.
subject
=
current_user
.
try
(
:username
)
token
[
:access
]
=
access
token
[
:access
]
=
access
token
token
...
...
app/services/projects/destroy_service.rb
View file @
d05f0030
...
@@ -27,7 +27,7 @@ module Projects
...
@@ -27,7 +27,7 @@ module Projects
project
.
destroy!
project
.
destroy!
unless
remove_registry_tags
unless
remove_registry_tags
raise_error
(
'Failed to remove project
image
registry. Please try again or contact administrator'
)
raise_error
(
'Failed to remove project
container
registry. Please try again or contact administrator'
)
end
end
unless
remove_repository
(
repo_path
)
unless
remove_repository
(
repo_path
)
...
...
app/views/projects/container_registry/_tag.html.haml
0 → 100644
View file @
d05f0030
%tr
.tag
%td
=
escape_once
(
tag
.
name
)
=
clipboard_button
(
clipboard_text:
"docker pull
#{
tag
.
path
}
"
)
%td
-
if
layer
=
tag
.
layers
.
first
%span
.has-tooltip
(
title=
"#{layer.revision}"
)
=
layer
.
short_revision
-
else
\-
%td
=
number_to_human_size
(
tag
.
total_size
)
·
=
pluralize
(
tag
.
layers
.
size
,
"layer"
)
%td
=
time_ago_in_words
(
tag
.
created_at
)
%td
.content
.controls.hidden-xs.pull-right
=
link_to
namespace_project_container_registry_path
(
@project
.
namespace
,
@project
,
tag
.
name
),
class:
'btn btn-remove has-tooltip'
,
title:
"Remove"
,
data:
{
confirm:
"Are you sure?"
},
method: :delete
do
=
icon
(
"trash cred"
)
app/views/projects/container_registry/index.html.haml
View file @
d05f0030
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
-
else
-
else
.table-holder
.table-holder
%table
.table.
build
s
%table
.table.
tag
s
%thead
%thead
%tr
%tr
%th
Name
%th
Name
...
@@ -36,23 +36,4 @@
...
@@ -36,23 +36,4 @@
%th
%th
-
@tags
.
each
do
|
tag
|
-
@tags
.
each
do
|
tag
|
%tr
=
render
'tag'
,
tag:
tag
%td
\ No newline at end of file
=
escape_once
(
tag
.
name
)
=
clipboard_button
(
clipboard_text:
"docker pull
#{
tag
.
path
}
"
)
%td
-
if
layer
=
tag
.
layers
.
first
%span
.has-tooltip
(
title=
"#{layer.revision}"
)
=
layer
.
short_revision
-
else
\-
%td
=
number_to_human_size
(
tag
.
total_size
)
·
=
pluralize
(
tag
.
layers
.
size
,
"layer"
)
%td
=
time_ago_in_words
(
tag
.
created_at
)
%td
.content
.controls.hidden-xs.pull-right
=
link_to
namespace_project_container_registry_path
(
@project
.
namespace
,
@project
,
tag
.
name
),
class:
'btn btn-remove has-tooltip'
,
title:
"Remove"
,
data:
{
confirm:
"Are you sure?"
},
method: :delete
do
=
icon
(
"trash cred"
)
lib/container_registry/client.rb
View file @
d05f0030
...
@@ -10,7 +10,7 @@ module ContainerRegistry
...
@@ -10,7 +10,7 @@ module ContainerRegistry
def
initialize
(
base_uri
,
options
=
{})
def
initialize
(
base_uri
,
options
=
{})
@base_uri
=
base_uri
@base_uri
=
base_uri
@faraday
=
Faraday
.
new
(
@base_uri
)
do
|
conn
|
@faraday
=
Faraday
.
new
(
@base_uri
)
do
|
conn
|
initialize_connection
(
conn
)
initialize_connection
(
conn
,
options
)
end
end
end
end
...
@@ -51,7 +51,7 @@ module ContainerRegistry
...
@@ -51,7 +51,7 @@ module ContainerRegistry
private
private
def
initialize_connection
(
conn
)
def
initialize_connection
(
conn
,
options
)
conn
.
request
:json
conn
.
request
:json
conn
.
headers
[
'Accept'
]
=
MANIFEST_VERSION
conn
.
headers
[
'Accept'
]
=
MANIFEST_VERSION
...
...
spec/features/container_registry_spec.rb
0 → 100644
View file @
d05f0030
require
'spec_helper'
describe
"Container Registry"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:repository
)
{
project
.
container_registry_repository
}
let
(
:tag_name
)
{
'latest'
}
let
(
:tags
)
{
[
tag_name
]
}
before
do
end
before
do
login_as
(
:user
)
project
.
team
<<
[
@user
,
:developer
]
stub_container_registry
(
*
tags
)
end
describe
'GET /:project/container_registry'
do
before
do
visit
namespace_project_container_registry_index_path
(
project
.
namespace
,
project
)
end
context
'when no tags'
do
let
(
:tags
)
{
[]
}
it
{
expect
(
page
).
to
have_content
(
'No images in Container Registry for this project'
)
}
end
context
'when there are tags'
do
it
{
expect
(
page
).
to
have_content
(
tag_name
)}
end
end
describe
'DELETE /:project/container_registry/tag'
do
before
do
visit
namespace_project_container_registry_index_path
(
project
.
namespace
,
project
)
end
it
do
expect_any_instance_of
(
::
ContainerRegistry
::
Tag
).
to
receive
(
:delete
).
and_return
(
true
)
click_on
'Remove'
end
end
end
\ No newline at end of file
spec/fixtures/container_registry/config_blob.json
0 → 100644
View file @
d05f0030
{
"architecture"
:
"amd64"
,
"config"
:{
"Hostname"
:
"b14cd8298755"
,
"Domainname"
:
""
,
"User"
:
""
,
"AttachStdin"
:
false
,
"AttachStdout"
:
false
,
"AttachStderr"
:
false
,
"Tty"
:
false
,
"OpenStdin"
:
false
,
"StdinOnce"
:
false
,
"Env"
:
null
,
"Cmd"
:
null
,
"Image"
:
""
,
"Volumes"
:
null
,
"WorkingDir"
:
""
,
"Entrypoint"
:
null
,
"OnBuild"
:
null
,
"Labels"
:
null
},
"container"
:
"b14cd82987550b01af9a666a2f4c996280a6152e66873134fae5a0f223dc5976"
,
"container_config"
:{
"Hostname"
:
"b14cd8298755"
,
"Domainname"
:
""
,
"User"
:
""
,
"AttachStdin"
:
false
,
"AttachStdout"
:
false
,
"AttachStderr"
:
false
,
"Tty"
:
false
,
"OpenStdin"
:
false
,
"StdinOnce"
:
false
,
"Env"
:
null
,
"Cmd"
:[
"/bin/sh"
,
"-c"
,
"#(nop) ADD file:033ab063740d9ff4dcfb1c69eccf25f91d88729f57cd5a73050e014e3e094aa0 in /"
],
"Image"
:
""
,
"Volumes"
:
null
,
"WorkingDir"
:
""
,
"Entrypoint"
:
null
,
"OnBuild"
:
null
,
"Labels"
:
null
},
"created"
:
"2016-04-01T20:53:00.160300546Z"
,
"docker_version"
:
"1.9.1"
,
"history"
:[{
"created"
:
"2016-04-01T20:53:00.160300546Z"
,
"created_by"
:
"/bin/sh -c #(nop) ADD file:033ab063740d9ff4dcfb1c69eccf25f91d88729f57cd5a73050e014e3e094aa0 in /"
}],
"os"
:
"linux"
,
"rootfs"
:{
"type"
:
"layers"
,
"diff_ids"
:[
"sha256:c56b7dabbc7aa730eeab07668bdcbd7e3d40855047ca9a0cc1bfed23a2486111"
]}}
spec/fixtures/container_registry/tag_manifest.json
0 → 100644
View file @
d05f0030
{
"schemaVersion"
:
2
,
"mediaType"
:
"application/vnd.docker.distribution.manifest.v2+json"
,
"config"
:{
"mediaType"
:
"application/octet-stream"
,
"size"
:
1145
,
"digest"
:
"sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac"
},
"layers"
:[{
"mediaType"
:
"application/vnd.docker.image.rootfs.diff.tar.gzip"
,
"size"
:
2319870
,
"digest"
:
"sha256:420890c9e918b6668faaedd9000e220190f2493b0693ee563ebd7b4cc754a57d"
}]}
spec/support/stub_gitlab_calls.rb
View file @
d05f0030
...
@@ -25,6 +25,18 @@ module StubGitlabCalls
...
@@ -25,6 +25,18 @@ module StubGitlabCalls
allow_any_instance_of
(
Project
).
to
receive
(
:builds_enabled?
).
and_return
(
false
)
allow_any_instance_of
(
Project
).
to
receive
(
:builds_enabled?
).
and_return
(
false
)
end
end
def
stub_container_registry
(
*
tags
)
allow_any_instance_of
(
ContainerRegistry
::
Client
).
to
receive
(
:repository_tags
).
and_return
(
{
"tags"
=>
tags
}
)
allow_any_instance_of
(
ContainerRegistry
::
Client
).
to
receive
(
:repository_manifest
).
and_return
(
JSON
.
load
(
File
.
read
(
Rails
.
root
+
'spec/fixtures/container_registry/tag_manifest.json'
))
)
allow_any_instance_of
(
ContainerRegistry
::
Client
).
to
receive
(
:blob
).
and_return
(
File
.
read
(
Rails
.
root
+
'spec/fixtures/container_registry/config_blob.json'
)
)
end
private
private
def
gitlab_url
def
gitlab_url
...
...
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