Class: RailsificationsController

Inherits:
MVCLI::Controller
  • Object
show all
Defined in:
app/controllers/railsifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/railsifications_controller.rb', line 10

def create
  command.output.puts "Setting up a chef kitchen in order to railsify your server."
  command.output.puts "This could take a while...."
  sleep(1)
  tmpdir = Pathname(Dir.tmpdir).join 'chef_kitchen'
  FileUtils.mkdir_p tmpdir
  Dir.chdir tmpdir do
    Bundler.with_clean_env do
      File.open('Gemfile', 'w') do |f|
        f.puts 'source "https://rubygems.org"'
        f.puts 'gem "knife-solo", ">= 0.3.0pre3"'
        f.puts 'gem "berkshelf"'
      end
      execute "bundle install --binstubs"
      execute "bin/knife solo init ."
      File.open 'Berksfile', 'w' do |f|
        f.puts "site :opscode"
        f.puts ""
        f.puts "cookbook 'runit', '>= 1.1.2'"
        f.puts "cookbook 'rackbox', github: 'hayesmp/rackbox-cookbook'"
      end
      execute "bin/berks install --path cookbooks/"
      execute "bin/knife solo prepare root@#{server.ipv4_address}"
      File.open('nodes/host.json', 'w') do |f|
        f.puts('{"run_list":["rackbox"],"rackbox":{"apps":{"unicorn":[{"appname":"app1","hostname":"app1"}]},"ruby":{"global_version":"2.0.0-p195","versions":["2.0.0-p195"]}}}')
      end

      FileUtils.rm_rf "#{server.ipv4_address}.json"
      FileUtils.mv "nodes/host.json", "nodes/#{server.ipv4_address}.json"

      execute "bin/knife solo cook root@#{server.ipv4_address}"
    end
  end
  return server
end