Project

General

Profile

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

foreman_docker / lib / foreman_docker / engine.rb @ ada932ab

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
    initializer 'foreman_docker.load_app_instance_data' do |app|
15
      app.config.paths['db/migrate'] += ForemanDocker::Engine.paths['db/migrate'].existent
16
    end
17

    
18
    initializer "foreman_docker.assets.precompile" do |app|
19
      app.config.assets.precompile += %w(foreman_docker/terminal.css foreman_docker/image_step.js)
20
    end
21

    
22
    initializer 'foreman_docker.configure_assets', :group => :assets do
23
      SETTINGS[:foreman_docker] =
24
        { :assets => { :precompile => ['foreman_docker/terminal.css',
25
                                       'foreman_docker/image_step.js'] } }
26
    end
27

    
28
    initializer 'foreman_docker.register_gettext', :after => :load_config_initializers do
29
      locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
30
      locale_domain = 'foreman_docker'
31

    
32
      Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
33
    end
34

    
35
    initializer 'foreman_docker.register_plugin', :after => :finisher_hook do
36
      Foreman::Plugin.register :foreman_docker do
37
        requires_foreman '> 1.4'
38
        compute_resource ForemanDocker::Docker
39

    
40
        sub_menu :top_menu, :containers_menu, :caption => N_('Containers'),
41
                                              :after => :monitor_menu do
42
          menu :top_menu, :containers,    :caption => N_('All containers'),
43
                                          :url_hash => { :controller => :containers,
44
                                                         :action => :index }
45
          menu :top_menu, :new_container, :caption => N_('New container'),
46
                                          :url_hash => { :controller => :containers,
47
                                                         :action => :new }
48
          menu :top_menu, :registries, :caption => N_('Registries'),
49
                                       :url_hash => { :controller => :registries,
50
                                                      :action => :index }
51
        end
52

    
53
        security_block :containers do
54
          permission :view_containers,    :containers         => [:index, :show,
55
                                                                  :auto_complete_image,
56
                                                                  :auto_complete_image_tags,
57
                                                                  :search_image]
58
          permission :commit_containers,  :containers         => [:commit]
59
          permission :create_containers,  :'containers/steps' => [:show, :update],
60
                                          :containers         => [:new]
61
          permission :destroy_containers, :containers         => [:destroy]
62
        end
63

    
64
        security_block :registries do
65
          permission :view_registries,    :registries         => [:index, :show]
66
          permission :create_registries,  :registries         => [:new, :create, :update, :edit]
67
          permission :destroy_registries, :registries         => [:destroy]
68
        end
69
      end
70

    
71
    end
72

    
73
    rake_tasks do
74
      load "#{ForemanDocker::Engine.root}/lib/foreman_docker/tasks/test.rake"
75
    end
76
  end
77

    
78
  # extend fog docker server and image models.
79
  require 'fog/fogdocker/models/compute/server'
80
  require 'fog/fogdocker/models/compute/image'
81
  require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/server', __FILE__)
82
  require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/image', __FILE__)
83
  Fog::Compute::Fogdocker::Server.send(:include, ::FogExtensions::Fogdocker::Server)
84
  Fog::Compute::Fogdocker::Image.send(:include, ::FogExtensions::Fogdocker::Image)
85
end