Module: RubyYacht::Plugins::Rails

Defined in:
lib/ruby_yacht/plugins/rails.rb

Overview

This module provides the plugin for managing Ruby on Rails apps.

Class Method Summary collapse

Class Method Details

.loadObject

This method loads the configuration for the Rails plugin.



5
6
7
8
9
# File 'lib/ruby_yacht/plugins/rails.rb', line 5

def self.load
  load_server_type
  load_hooks
  load_environment_variables
end

.load_environment_variablesObject

This method loads the hooks for setting environment variables for the Rails apps.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruby_yacht/plugins/rails.rb', line 54

def self.load_environment_variables
  RubyYacht.configure do
    add_hooks app_server_type: :rails, container_type: :app do
      during :initialize_app_environment do
        set_environment_variable 'RAILS_ENV' do
          @project.rails_environment == 'development' ? nil : @project.rails_environment
        end
        set_environment_variable 'SECRET_KEY_BASE' do
          @project.rails_secret_key_base
        end
        set_environment_variable 'EXCLUDED_GEM_GROUPS' do
          groups = @project.rails_excluded_gem_groups.join(' ')
          groups = '""' if groups == ''
          groups
        end
      end
    end
  end
end

.load_hooksObject

This method loads the configuration for the Rails hooks.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_yacht/plugins/rails.rb', line 25

def self.load_hooks
  RubyYacht.configure do
    add_hooks(app_server_type: :rails, container_type: :app, script_folder: File.join(File.dirname(__FILE__), 'rails', 'scripts')) do
      during(:install_libraries) { run_script :ruby, 'install_gems.rb' }
      
      after(:build_checkout) { command 'bundle install --clean' }
      
      if RubyYacht.configuration.find_server_type(:mysql)
        during :load_database_seeds do
          container_type :database
          database_server_type :mysql
          run_script :ruby, 'load_seeds.rb'
        end
      end
      
      during :build_new_app do
        run_script :ruby, 'build_new_app.rb'
      end

      before(:startup) { run_script :ruby, 'update_rails_config.rb' }
      before(:startup) { run_script :ruby, 'prepare_rails_for_launch.rb' }

      during(:startup) { command 'rails s -b 0.0.0.0 -p $APP_PORT' }
    end
  end
end

.load_server_typeObject

This method loads the configuration for the Rails server type.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_yacht/plugins/rails.rb', line 12

def self.load_server_type
  RubyYacht.configure do
    server_type :rails do
      container_type :app
      baseline_image 'ruby:2.3'
      project_attribute name: :environment, default: 'development'
      project_attribute name: :excluded_gem_groups, default: []
      project_attribute name: :secret_key_base
    end
  end
end