Project

General

Profile

Revision ada932ab

Added by Dmitri Dolguikh over 7 years ago

Fixes #7647: Added support for external registries

View differences:

app/controllers/containers_controller.rb
1
# rubocop:disable Metrics/ClassLength
1 2
class ContainersController < ::ApplicationController
2 3
  before_filter :find_container, :only => [:show, :auto_complete_image, :auto_complete_image_tags,
3 4
                                           :search_image, :commit]
5
  before_filter :find_registry, :only => [:auto_complete_image, :auto_complete_image_tags,
6
                                          :search_image]
4 7

  
5 8
  def index
6 9
    @container_resources = allowed_resources.select { |cr| cr.provider == 'Docker' }
......
34 37
  end
35 38

  
36 39
  def auto_complete_image
37
    render :text => @container.compute_resource.exist?(params[:search]).to_s
40
    exist = if @registry.nil?
41
              @container.compute_resource.exist?(params[:search])
42
            else
43
              registry_auto_complete_image(params[:search])
44
            end
45
    render :text => exist.to_s
46
  end
47

  
48
  def registry_auto_complete_image(term)
49
    result = ::Service::RegistryApi.new(:url => @registry.url).search(term)
50
    registry_name = term.split('/').size > 1 ? term :
51
        'library/' + term
52
    result['results'].any? { |r| r['name'] == registry_name }
38 53
  end
39 54

  
40 55
  def auto_complete_image_tags
41 56
    # This is the format jQuery UI autocomplete expects
42
    tags = @container.compute_resource.tags(params[:search])
57
    tags = if @registry.nil?
58
             @container.compute_resource.tags(params[:search])
59
           else
60
             registry_auto_complete_image_tags(params[:search])
61
           end
43 62
    respond_to do |format|
44 63
      format.js do
45 64
        tags.map! { |tag| { :label => CGI.escapeHTML(tag), :value => CGI.escapeHTML(tag) } }
......
48 67
    end
49 68
  end
50 69

  
70
  def registry_auto_complete_image_tags(term)
71
    ::Service::RegistryApi.new(:url => @registry.url).list_repository_tags(term).keys
72
  end
73

  
51 74
  def commit
52 75
    Docker::Container.get(@container.uuid).commit(:author  => params[:commit][:author],
53 76
                                                  :repo    => params[:commit][:repo],
......
63 86
  end
64 87

  
65 88
  def search_image
66
    images = @container.compute_resource.search(params[:search])
89
    images = if @registry.nil?
90
               @container.compute_resource.search(params[:search])
91
             else
92
               r = ::Service::RegistryApi.new(:url => @registry.url).search(params[:search])
93
               r['results']
94
             end
67 95
    respond_to do |format|
68 96
      format.js { render :partial => 'image_search_results', :locals => { :images => images } }
69 97
    end
......
118 146
    @container = Container.authorized("#{action_permission}_#{controller_name}".to_sym)
119 147
                          .find(params[:id])
120 148
  end
149

  
150
  def find_registry
151
    return if params[:registry_id].empty?
152
    @registry = DockerRegistry.authorized("#{action_permission}_#{controller_name}".to_sym)
153
    .find(params[:registry_id])
154
  end
121 155
end

Also available in: Unified diff