summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-12 13:03:04 -0500
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-12 13:03:04 -0500
commit5c2f2fd2890b7efd7a63f9a371b2f795f2e9fa43 (patch)
tree473a1f9f2fc6c9d33a968218338815e2d84479af
parent4d84ba43d8db6a205e79dd8cf723be7ceebf6925 (diff)
downloadgitlab-ce-5c2f2fd2890b7efd7a63f9a371b2f795f2e9fa43.tar.gz
Fix CI tests
-rw-r--r--app/controllers/projects/container_registry_controller.rb1
-rw-r--r--app/helpers/gitlab_routing_helper.rb2
-rw-r--r--app/models/ability.rb2
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/project.rb4
-rw-r--r--app/services/jwt/container_registry_authentication_service.rb2
-rw-r--r--app/services/projects/destroy_service.rb4
-rw-r--r--app/services/projects/transfer_service.rb2
-rw-r--r--app/views/projects/container_registry/_tag.html.haml9
-rw-r--r--app/views/projects/container_registry/index.html.haml5
-rw-r--r--lib/container_registry/client.rb2
-rw-r--r--lib/container_registry/repository.rb4
-rw-r--r--spec/features/container_registry_spec.rb12
13 files changed, 31 insertions, 20 deletions
diff --git a/app/controllers/projects/container_registry_controller.rb b/app/controllers/projects/container_registry_controller.rb
index 82c621b29e4..c470789a5bb 100644
--- a/app/controllers/projects/container_registry_controller.rb
+++ b/app/controllers/projects/container_registry_controller.rb
@@ -1,7 +1,6 @@
class Projects::ContainerRegistryController < Projects::ApplicationController
before_action :authorize_read_container_registry!
before_action :authorize_update_container_registry!, only: [:destroy]
- before_action :tag, except: [:index]
layout 'project'
def index
diff --git a/app/helpers/gitlab_routing_helper.rb b/app/helpers/gitlab_routing_helper.rb
index dd9536b1460..2ce2d4e694f 100644
--- a/app/helpers/gitlab_routing_helper.rb
+++ b/app/helpers/gitlab_routing_helper.rb
@@ -34,7 +34,7 @@ module GitlabRoutingHelper
end
def project_container_registry_path(project, *args)
- namespace_project_container_registry_index_url(project.namespace, project, *args)
+ namespace_project_container_registry_index_path(project.namespace, project, *args)
end
def activity_project_path(project, *args)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 59d5195f5b9..2465c1f424c 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -291,7 +291,7 @@ class Ability
rules += named_abilities('build')
end
- unless project.container_registry_enabled
+ unless project.container_registry_enabled && Gitlab.config.registry.enabled
rules += named_abilities('container_registry')
end
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 0f61cee7888..62ef6de5db1 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -128,7 +128,7 @@ class Namespace < ActiveRecord::Base
gitlab_shell.add_namespace(path_was)
if any_project_has_container_registry_tags?
- raise Exception.new('namespace cannot be moved, because at least one project has tags in container registry')
+ raise Exception.new('Namespace cannot be moved, because at least one project has tags in container registry')
end
if gitlab_shell.mv_namespace(path_was, path)
diff --git a/app/models/project.rb b/app/models/project.rb
index d3ae7803bea..e5ace7d755b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -377,7 +377,7 @@ class Project < ActiveRecord::Base
def container_registry_repository
@container_registry_repository ||= begin
- token = Jwt::ContainerRegistryAuthenticationService.full_access_token(path_with_namespace)
+ token = JWT::ContainerRegistryAuthenticationService.full_access_token(path_with_namespace)
url = Gitlab.config.registry.api_url
host_port = Gitlab.config.registry.host_port
registry = ContainerRegistry::Registry.new(url, token: token, path: host_port)
@@ -814,7 +814,7 @@ class Project < ActiveRecord::Base
if has_container_registry_tags?
# we currently doesn't support renaming repository if it contains tags in container registry
- raise Exception.new('repository cannot be renamed, due to tags in container registry')
+ raise Exception.new('Project cannot be renamed, because tags are present in its container registry')
end
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
diff --git a/app/services/jwt/container_registry_authentication_service.rb b/app/services/jwt/container_registry_authentication_service.rb
index bc7e663caa6..91bad347278 100644
--- a/app/services/jwt/container_registry_authentication_service.rb
+++ b/app/services/jwt/container_registry_authentication_service.rb
@@ -14,7 +14,7 @@ module JWT
def self.full_access_token(*names)
registry = Gitlab.config.registry
- token = ::Jwt::RSAToken.new(registry.key)
+ token = ::JWT::RSAToken.new(registry.key)
token.issuer = registry.issuer
token.audience = AUDIENCE
token[:access] = names.map do |name|
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb
index 8e2e46346ca..0ff2bc3cb81 100644
--- a/app/services/projects/destroy_service.rb
+++ b/app/services/projects/destroy_service.rb
@@ -64,7 +64,9 @@ module Projects
end
def remove_registry_tags
- project.image_registry.delete_tags
+ return unless Gitlab.config.registry.enabled
+
+ project.container_registry_repository.delete_tags
end
def raise_error(message)
diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb
index 0d72286dec7..03b57dea51e 100644
--- a/app/services/projects/transfer_service.rb
+++ b/app/services/projects/transfer_service.rb
@@ -36,7 +36,7 @@ module Projects
if project.has_container_registry_tags?
# we currently doesn't support renaming repository if it contains tags in container registry
- raise TransferError.new('Repository cannot be renamed, due to tags in container registry')
+ raise TransferError.new('Project cannot be transferred, because tags are present in its container registry')
end
project.expire_caches_before_rename(old_path)
diff --git a/app/views/projects/container_registry/_tag.html.haml b/app/views/projects/container_registry/_tag.html.haml
index f97988d20cf..bf816d109b6 100644
--- a/app/views/projects/container_registry/_tag.html.haml
+++ b/app/views/projects/container_registry/_tag.html.haml
@@ -14,7 +14,8 @@
= 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")
+ - if can?(current_user, :update_container_registry, @project)
+ %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")
diff --git a/app/views/projects/container_registry/index.html.haml b/app/views/projects/container_registry/index.html.haml
index 701f1a86b56..ea7c4faaaec 100644
--- a/app/views/projects/container_registry/index.html.haml
+++ b/app/views/projects/container_registry/index.html.haml
@@ -18,7 +18,7 @@
%code
docker login #{Gitlab.config.registry.host_port}
%br
- Then you are free to create and upload a container images with build and push commands:
+ Then you are free to create and upload a container image with build and push commands:
%pre
docker build -t #{escape_once(@project.container_registry_repository_url)} .
%br
@@ -33,7 +33,8 @@
%th Image ID
%th Size
%th Created
- %th
+ - if can?(current_user, :update_container_registry, @project)
+ %th
- @tags.each do |tag|
= render 'tag', tag: tag \ No newline at end of file
diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb
index 0bfb6baffd4..c250a4b6946 100644
--- a/lib/container_registry/client.rb
+++ b/lib/container_registry/client.rb
@@ -55,7 +55,7 @@ module ContainerRegistry
conn.request :json
conn.headers['Accept'] = MANIFEST_VERSION
- conn.response :json, :content_type => /\bjson$/
+ conn.response :json, content_type: /\bjson$/
if options[:user] && options[:password]
conn.request(:basic_auth, options[:user].to_s, options[:password].to_s)
diff --git a/lib/container_registry/repository.rb b/lib/container_registry/repository.rb
index f01330f3648..b30cb527b60 100644
--- a/lib/container_registry/repository.rb
+++ b/lib/container_registry/repository.rb
@@ -30,19 +30,21 @@ module ContainerRegistry
def tags
return @tags if defined?(@tags)
return [] unless manifest && manifest['tags']
+
@tags = manifest['tags'].map do |tag|
ContainerRegistry::Tag.new(self, tag)
end
- @tags ||= []
end
def delete_tags
return unless tags
+
tags.each(:delete)
end
def mount_blob(blob)
return unless blob
+
client.repository_mount_blob(name, blob.digest, blob.repository.name)
end
diff --git a/spec/features/container_registry_spec.rb b/spec/features/container_registry_spec.rb
index 7bef7a2ee81..6c4d675fd6a 100644
--- a/spec/features/container_registry_spec.rb
+++ b/spec/features/container_registry_spec.rb
@@ -5,14 +5,18 @@ describe "Container Registry" do
let(:repository) { project.container_registry_repository }
let(:tag_name) { 'latest' }
let(:tags) { [tag_name] }
-
- before do
+ let(:registry_settings) do
+ {
+ enabled: true
+ }
end
before do
login_as(:user)
project.team << [@user, :developer]
stub_container_registry(*tags)
+ allow(Gitlab.config.registry).to receive_messages(registry_settings)
+ allow(JWT::ContainerRegistryAuthenticationService).to receive(:full_access_token).and_return('token')
end
describe 'GET /:project/container_registry' do
@@ -22,6 +26,7 @@ describe "Container Registry" do
context 'when no tags' do
let(:tags) { [] }
+
it { expect(page).to have_content('No images in Container Registry for this project') }
end
@@ -37,7 +42,8 @@ describe "Container Registry" do
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
+end