class EbDeployer::Generators::InstallGenerator

Constants

DEFAULT_STACK_NAME

Public Instance Methods

do_install() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 12
def do_install
  in_root do
    copy_file 'eb_deployer.rake', 'lib/tasks/eb_deployer.rake'
    template 'eb_deployer.yml.erb', 'config/eb_deployer.yml'
    setup_database
  end
end

Private Instance Methods

alphanumeric_name() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 69
def alphanumeric_name
  app_name.gsub(/-/, '')
end
app_name() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 77
def app_name
  File.basename(Dir.pwd).downcase.gsub(/[^0-9a-z]/, '-').gsub(/--/, '-')
end
db_password() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 57
def db_password
  "PleaseChangeMe"
end
secure_random(length) click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 73
def secure_random(length)
  SecureRandom.hex(length)
end
setup_database() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 21
def setup_database
  gem 'pg'
  setup_database_yml
  copy_file 'postgres_rds.json', 'config/rds.json'
  directory 'ebextensions', '.ebextensions'
end
setup_database_yml() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 28
      def setup_database_yml
        gsub_file('config/database.yml', /^production:.+/m) do |match|
          prod_start = false
          match.split("\n").map do |l|
            case l
            when /^production/
              prod_start = true
              "# #{l}"
            when /^\s+/
              prod_start ? "# #{l}" : l
            else
              prod_start = false
              l
            end
          end.join("\n")
        end
        append_to_file('config/database.yml', <<-YAML)


production:
  adapter: postgresql
  database: <%= ENV['DATABASE_NAME'] || '#{app_name}_production' %>
  host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
  port: <%= ENV['DATABASE_PORT'] || 5432 %>
  username: <%= ENV['DATABASE_USERNAME'] || #{ENV['USER'].inspect} %>
  password: <%= ENV['DATABASE_PASSWORD'] %>
  min_messages: ERROR
YAML
      end
solution_stack_name() click to toggle source
# File lib/generators/eb_deployer/install/install_generator.rb, line 61
def solution_stack_name
  Aws::ElasticBeanstalk.Client.new.list_available_solution_stacks[:solution_stacks].find do |s|
    s =~ /Amazon Linux/ && s =~ /running Ruby 2.1 \(Passenger Standalone\)/
  end
rescue
  DEFAULT_STACK_NAME
end