Project

General

Profile

Download (4.79 KB) Statistics
| Branch: | Tag: | Revision:

foreman_docker / lib / foreman_docker / engine.rb @ 9f0918fc

1
require 'fast_gettext'
2
require 'gettext_i18n_rails'
3
require 'fog'
4
require 'fog/fogdocker'
5
require 'wicked'
6
require 'docker'
7

    
8
module ForemanDocker
9
  # Inherit from the Rails module of the parent app (Foreman), not the plugin.
10
  # Thus, inherits from ::Rails::Engine and not from Rails::Engine
11
  class Engine < ::Rails::Engine
12
    engine_name 'foreman_docker'
13

    
14
    config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
15
    config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
16

    
17
    initializer 'foreman_docker.load_app_instance_data' do |app|
18
      app.config.paths['db/migrate'] += ForemanDocker::Engine.paths['db/migrate'].existent
19
    end
20

    
21
    initializer "foreman_docker.assets.precompile" do |app|
22
      app.config.assets.precompile += %w(foreman_docker/autocomplete.css
23
                                         foreman_docker/terminal.css
24
                                         foreman_docker/image_step.js)
25
    end
26

    
27
    initializer 'foreman_docker.configure_assets', :group => :assets do
28
      SETTINGS[:foreman_docker] =
29
        { :assets => { :precompile => ['foreman_docker/autocomplete.css',
30
                                       'foreman_docker/terminal.css',
31
                                       'foreman_docker/image_step.js'] } }
32
    end
33

    
34
    initializer 'foreman_docker.register_gettext', :after => :load_config_initializers do
35
      locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
36
      locale_domain = 'foreman_docker'
37

    
38
      Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
39
    end
40

    
41
    initializer 'foreman_docker.register_plugin', :after => :finisher_hook do
42
      Foreman::Plugin.register :foreman_docker do
43
        requires_foreman '> 1.4'
44
        compute_resource ForemanDocker::Docker
45

    
46
        sub_menu :top_menu, :containers_menu, :caption => N_('Containers'),
47
                                              :after => :monitor_menu do
48
          menu :top_menu, :containers,    :caption => N_('All containers'),
49
                                          :url_hash => { :controller => :containers,
50
                                                         :action => :index }
51
          menu :top_menu, :new_container, :caption => N_('New container'),
52
                                          :url_hash => { :controller => :containers,
53
                                                         :action => :new }
54
          menu :top_menu, :registries, :caption => N_('Registries'),
55
                                       :url_hash => { :controller => :registries,
56
                                                      :action => :index }
57
        end
58

    
59
        security_block :containers do
60
          permission :view_containers,    :containers         => [:index, :show]
61
          permission :commit_containers,  :containers         => [:commit]
62
          permission :create_containers,  :'containers/steps' => [:show, :update],
63
                                          :containers         => [:new]
64
          permission :destroy_containers, :containers         => [:destroy]
65
          permission :power_compute_resources_vms, :containers => [:power]
66
        end
67

    
68
        security_block :registries do
69
          permission :view_registries,    :registries         => [:index, :show]
70
          permission :create_registries,  :registries         => [:new, :create, :update, :edit]
71
          permission :destroy_registries, :registries         => [:destroy]
72
        end
73

    
74
        security_block :image_search do
75
          permission :search_repository_image_search,
76
                     :image_search => [:auto_complete_repository_name,
77
                                       :auto_complete_image_tag,
78
                                       :search_repository]
79
        end
80
      end
81
    end
82

    
83
    rake_tasks do
84
      load "#{ForemanDocker::Engine.root}/lib/foreman_docker/tasks/test.rake"
85
    end
86

    
87
    require 'fog/fogdocker/models/compute/server'
88
    require 'fog/fogdocker/models/compute/image'
89
    require 'fog/fogdocker/models/compute/images'
90
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/server',
91
                             __FILE__)
92
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/image',
93
                             __FILE__)
94
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/images',
95
                             __FILE__)
96
    config.to_prepare do
97
      Fog::Compute::Fogdocker::Server.send(:include, ::FogExtensions::Fogdocker::Server)
98
      Fog::Compute::Fogdocker::Image.send(:include, ::FogExtensions::Fogdocker::Image)
99
      # Compatibility fixes - to be removed once 1.7 compatibility is no longer required
100
      Fog::Compute::Fogdocker::Images.send(:include, ::FogExtensions::Fogdocker::Images)
101
      ::Taxonomy.send(:include, ForemanDocker::TaxonomyExtensions)
102
    end
103
  end
104
end