diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-11 12:05:30 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-04-11 12:05:30 +0000 |
commit | cf1beb003bc538fded81c26bb360b1ec9525937e (patch) | |
tree | b45e21cb7ea6a4c3198b44d214548273ca9e9f4e | |
parent | 7df8118a8279d3ed28cad21bbb27e7336dbbc8f2 (diff) | |
parent | bb294b91d7a74e00ea9e93011fdad47d88c7cfdf (diff) | |
download | gitlab-ce-cf1beb003bc538fded81c26bb360b1ec9525937e.tar.gz |
Merge branch 'fix/gb/improve-container-registry-clipboard-links' into 'master'
Fix container repository/tag location text copied into the clipboard
Closes #30695
See merge request !10587
-rw-r--r-- | app/models/container_repository.rb | 4 | ||||
-rw-r--r-- | app/views/projects/registry/repositories/_image.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/registry/repositories/_tag.html.haml | 2 | ||||
-rw-r--r-- | lib/container_registry/tag.rb | 4 | ||||
-rw-r--r-- | spec/lib/container_registry/tag_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/container_repository_spec.rb | 55 | ||||
-rw-r--r-- | spec/views/projects/registry/repositories/index.html.haml_spec.rb | 36 |
7 files changed, 88 insertions, 22 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 9682df3a586..82f4182d59a 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -23,6 +23,10 @@ class ContainerRepository < ActiveRecord::Base @path ||= [project.full_path, name].select(&:present?).join('/') end + def location + File.join(registry.path, path) + end + def tag(tag) ContainerRegistry::Tag.new(self, tag) end diff --git a/app/views/projects/registry/repositories/_image.html.haml b/app/views/projects/registry/repositories/_image.html.haml index d183ce34a3a..8bc78f8d018 100644 --- a/app/views/projects/registry/repositories/_image.html.haml +++ b/app/views/projects/registry/repositories/_image.html.haml @@ -4,7 +4,7 @@ = icon('chevron-down', 'aria-hidden': 'true') = escape_once(image.path) - = clipboard_button(clipboard_text: "docker pull #{image.path}") + = clipboard_button(clipboard_text: "docker pull #{image.location}") .controls.hidden-xs.pull-right = link_to namespace_project_container_registry_path(@project.namespace, @project, image), diff --git a/app/views/projects/registry/repositories/_tag.html.haml b/app/views/projects/registry/repositories/_tag.html.haml index 854b7d0ebf7..378a23f07e6 100644 --- a/app/views/projects/registry/repositories/_tag.html.haml +++ b/app/views/projects/registry/repositories/_tag.html.haml @@ -1,7 +1,7 @@ %tr.tag %td = escape_once(tag.name) - = clipboard_button(text: "docker pull #{tag.path}") + = clipboard_button(text: "docker pull #{tag.location}") %td - if tag.revision %span.has-tooltip{ title: "#{tag.revision}" } diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb index d00e6191e7e..728deea224f 100644 --- a/lib/container_registry/tag.rb +++ b/lib/container_registry/tag.rb @@ -29,6 +29,10 @@ module ContainerRegistry "#{repository.path}:#{name}" end + def location + "#{repository.location}:#{name}" + end + def [](key) return unless manifest diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index bc1912d8e6c..f8fffbdca41 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -50,6 +50,13 @@ describe ContainerRegistry::Tag do end end + describe '#location' do + it 'returns a full location of the tag' do + expect(tag.location) + .to eq 'registry.gitlab/group/test:tag' + end + end + context 'manifest processing' do context 'schema v1' do before do diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index f7ee0b57072..6d6c9f2adfc 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -4,7 +4,7 @@ describe ContainerRepository do let(:group) { create(:group, name: 'group') } let(:project) { create(:project, path: 'test', group: group) } - let(:container_repository) do + let(:repository) do create(:container_repository, name: 'my_image', project: project) end @@ -23,48 +23,48 @@ describe ContainerRepository do describe 'associations' do it 'belongs to the project' do - expect(container_repository).to belong_to(:project) + expect(repository).to belong_to(:project) end end describe '#tag' do it 'has a test tag' do - expect(container_repository.tag('test')).not_to be_nil + expect(repository.tag('test')).not_to be_nil end end describe '#path' do it 'returns a full path to the repository' do - expect(container_repository.path).to eq('group/test/my_image') + expect(repository.path).to eq('group/test/my_image') end end describe '#manifest' do - subject { container_repository.manifest } - - it { is_expected.not_to be_nil } + it 'returns non-empty manifest' do + expect(repository.manifest).not_to be_nil + end end describe '#valid?' do - subject { container_repository.valid? } - - it { is_expected.to be_truthy } + it 'is a valid repository' do + expect(repository).to be_valid + end end describe '#tags' do - subject { container_repository.tags } - - it { is_expected.not_to be_empty } + it 'returns non-empty tags list' do + expect(repository.tags).not_to be_empty + end end describe '#has_tags?' do it 'has tags' do - expect(container_repository).to have_tags + expect(repository).to have_tags end end describe '#delete_tags!' do - let(:container_repository) do + let(:repository) do create(:container_repository, name: 'my_image', tags: %w[latest rc1], project: project) @@ -72,21 +72,36 @@ describe ContainerRepository do context 'when action succeeds' do it 'returns status that indicates success' do - expect(container_repository.client) + expect(repository.client) .to receive(:delete_repository_tag) .and_return(true) - expect(container_repository.delete_tags!).to be_truthy + expect(repository.delete_tags!).to be_truthy end end context 'when action fails' do it 'returns status that indicates failure' do - expect(container_repository.client) + expect(repository.client) .to receive(:delete_repository_tag) .and_return(false) - expect(container_repository.delete_tags!).to be_falsey + expect(repository.delete_tags!).to be_falsey + end + end + end + + describe '#location' do + context 'when registry is running on a custom port' do + before do + stub_container_registry_config(enabled: true, + api_url: 'http://registry.gitlab:5000', + host_port: 'registry.gitlab:5000') + end + + it 'returns a full location of the repository' do + expect(repository.location) + .to eq 'registry.gitlab:5000/group/test/my_image' end end end @@ -102,7 +117,7 @@ describe ContainerRepository do context 'when repository is not a root repository' do it 'returns false' do - expect(container_repository).not_to be_root_repository + expect(repository).not_to be_root_repository end end end diff --git a/spec/views/projects/registry/repositories/index.html.haml_spec.rb b/spec/views/projects/registry/repositories/index.html.haml_spec.rb new file mode 100644 index 00000000000..ceeace3dc8d --- /dev/null +++ b/spec/views/projects/registry/repositories/index.html.haml_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'projects/registry/repositories/index', :view do + let(:group) { create(:group, path: 'group') } + let(:project) { create(:empty_project, group: group, path: 'test') } + + let(:repository) do + create(:container_repository, project: project, name: 'image') + end + + before do + stub_container_registry_config(enabled: true, + host_port: 'registry.gitlab', + api_url: 'http://registry.gitlab') + + stub_container_registry_tags(repository: :any, tags: [:latest]) + + assign(:project, project) + assign(:images, [repository]) + + allow(view).to receive(:can?).and_return(true) + end + + it 'contains container repository path' do + render + + expect(rendered).to have_content 'group/test/image' + end + + it 'contains attribute for copying tag location into clipboard' do + render + + expect(rendered).to have_css 'button[data-clipboard-text="docker pull ' \ + 'registry.gitlab/group/test/image:latest"]' + end +end |