salted-rails 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/README.md +65 -20
  2. data/init.sh +64 -0
  3. data/lib/salted-rails.rb +4 -6
  4. data/lib/salted-rails/capistrano_helper.rb +106 -0
  5. data/lib/salted-rails/cloud_vbguest_installer.rb +14 -0
  6. data/lib/salted-rails/config.rb +212 -0
  7. data/lib/salted-rails/helper_base.rb +90 -0
  8. data/lib/salted-rails/vagrant_helper.rb +159 -0
  9. data/lib/salted-rails/version.rb +3 -0
  10. data/lib/salted_rails_base.rb +6 -0
  11. data/pillar/capistrano/top.sls +1 -1
  12. data/pillar/common.sls +5 -0
  13. data/pillar/vagrant/top.sls +1 -1
  14. data/salt/bin/change_mirror.sh +29 -20
  15. data/salt/bin/fix_hostname.sh +6 -0
  16. data/salt/bin/provision +37 -0
  17. data/salt/capistrano/deploy_requirements.sls +5 -0
  18. data/salt/capistrano/minion +8 -4
  19. data/salt/capistrano/top.sls +1 -5
  20. data/salt/ci/cruisecontrolrb.sls +72 -0
  21. data/salt/ci/teamcity/etc/init.d/teamcity +17 -0
  22. data/salt/ci/teamcity/init.sls +58 -0
  23. data/salt/databases/client.sls +18 -0
  24. data/salt/{common.sls → databases/init.sls} +1 -16
  25. data/salt/databases/phpmyadmin/etc/nginx/{sites-available → admin.d}/phpmyadmin.conf +1 -1
  26. data/salt/databases/phpmyadmin/init.sls +2 -11
  27. data/salt/databases/server.sls +19 -0
  28. data/salt/editors/gvim.sls +5 -0
  29. data/salt/editors/rubymine.sls +51 -0
  30. data/salt/gui/init.sls +3 -0
  31. data/salt/gui/lxde.sls +5 -0
  32. data/salt/gui/x2go.sls +23 -0
  33. data/salt/lang/java/etc/profile.d/java.sh +2 -0
  34. data/salt/lang/java/init.sls +48 -0
  35. data/salt/lang/php/composer.sls +0 -3
  36. data/salt/lang/ruby.sls +3 -3
  37. data/salt/lang/ruby.sls.bak +3 -3
  38. data/salt/railsapp/gems.sls +16 -3
  39. data/salt/railsapp/init.sls +1 -0
  40. data/salt/railsapp/mysql_database.sls +11 -6
  41. data/salt/salt/minion/init.sls +19 -18
  42. data/salt/vagrant/minion +8 -4
  43. data/salt/vagrant/minion.sls +4 -5
  44. data/salt/vagrant/top.sls +32 -6
  45. data/salt/www/admin/etc/nginx/nginx.conf +53 -0
  46. data/salt/{databases/phpmyadmin → www/admin}/etc/nginx/sites-available/.gitignore +0 -0
  47. data/salt/www/admin/etc/nginx/sites-available/phpmyadmin.conf +7 -0
  48. data/salt/www/admin/init.sls +31 -0
  49. data/salt/www/nginx/init.sls +17 -4
  50. data/salt/www/users.sls +4 -0
  51. data/salted-rails.gemspec +1 -1
  52. metadata +30 -13
  53. data/lib/salted_rails/capistrano.rb +0 -8
  54. data/lib/salted_rails/vagrant_helper.rb +0 -169
  55. data/lib/salted_rails/version.rb +0 -5
  56. data/salt/capistrano.sls +0 -0
  57. data/salt/develop/init.sls +0 -3
  58. data/salt/echo_pillar.sls +0 -9
  59. data/salt/run-standalone +0 -3
  60. data/salt/vagrant.sls +0 -0
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Salted-Rails
2
2
 
3
- Salted-Rails: Provision rails using salt to vagrant or capistrano controlled systems
3
+ Salted-Rails: Provision a vagrant machine for rails using salt.
4
4
 
5
- This gem inspects .ruby-version, config/database.yml, Gemfile and Gemfile.lock to generate salt pillar files to control the configuration of the system.
5
+ This gem inspects your rails app configuration to work out what needs to be installed in the virtual machine.
6
6
 
7
- THIS GEM IS IN THE EXPERIMENTAL STAGE (pre pre alpha)! EXPECT THINGS TO CHANGE AND BREAK WITHOUT NOTICE!
7
+ THIS GEM IS IN ALPHA STAGE! THINGS MAY CHANGE AND BREAK WITHOUT NOTICE!
8
+
9
+ It Inspects:
10
+ * .ruby-version / .rvmrc to control the version of ruby installed (using rbenv)
11
+ * config/database.yml to create users and databases
12
+ * Gemfile and Gemfile.lock to preload gems into the system, and trigger the installation of packages required by gems
8
13
 
9
14
  This configures vagrant in the way that I personally like:
10
15
  * ubunutu 12.04 (LTS) 32bit from cloud-images.ubuntu.com (up to date packages and more memory free for systems < 4GB memory)
@@ -23,18 +28,62 @@ Add as a vagrant plugin
23
28
 
24
29
  vagrant plugin add salted-rails
25
30
 
26
- And then adjust your Vagrantfile as follows:
31
+ And then adjust your Vagrantfile as follows (accepting all the defaults, one machine):
32
+
33
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
34
+
35
+ if defined? SaltedRails::Config
36
+ salted_config = SaltedRails::Config.new(File.dirname(__FILE__))
37
+ salted_config.configure_vagrant(config)
38
+ end
39
+
40
+ # .... etc ....
41
+ end
42
+
43
+ Or for a more complicated example:
27
44
 
28
- require 'salted_rails/vagrant_helper'
29
- vagrant_helper = SaltedRails::VagrantHelper.new(File.dirname(__FILE__))
30
45
  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
31
- vagrant_helper.configure_vagrant(config)
32
- vagrant_helper.configure_ubuntu_mirror(config, 'mirror') # best (ping not bandwidth?) mirror
33
- vagrant_helper.configure_digital_ocean(config)
34
- vagrant_helper.configure_salt(config)
35
- vagrant_helper.configure_ports(config)
36
- # example - override default key
37
- # config.ssh.private_key_path = '~/.ssh/id_rsa_Another'
46
+
47
+ if defined? SaltedRails::Config
48
+ salted_config = SaltedRails::Config.new(File.dirname(__FILE__))
49
+
50
+ # On the guest run the following to copy all these files/firectories to vagrant home directory
51
+ # cd /srv/salt/generated/home ; cp -R .[a-z]* ~vagrant
52
+ # note .ssh/known_hosts and .ssh/authorized_hosts are renamed with .copy_from_home appended
53
+ salted_config.copy_from_home = %w{ .vim .vimrc .gitconfig .ssh .tmux .tmux.conf }
54
+
55
+ # if you have multiple ssh keys, you can select which one
56
+ salted_config.private_key_path = '~/.ssh/id_rsa_project' if File.exist? '~/.ssh/id_rsa_project'
57
+
58
+ # override default domain
59
+ salted_config.domain = 'mydomain.com'
60
+
61
+ # Define a machine dev
62
+ salted_config.define('dev') do |machine_config|
63
+ end
64
+
65
+ salted_config.define('qa') do |machine_config|
66
+ # use my ISP's mirror
67
+ salted_config.mirror = 'internode'
68
+
69
+ # explicitly specify memory
70
+ machine_config.memory = 1024
71
+
72
+ # add extra roles, which will install extra packages and increase teh defsault memory allocation
73
+
74
+ # two continuous integration packages
75
+ # browse http://localhost:8111
76
+ machine_config.roles <<= 'teamcity'
77
+
78
+ # browse http://localhost:3333
79
+ machine_config.roles <<= 'curisecontrolrb'
80
+
81
+ # gui also configures virtualbox for standard rather than headless mode
82
+ machine_config.roles <<= 'gui'
83
+ end
84
+
85
+ salted_config.configure_vagrant(config)
86
+ end
38
87
  end
39
88
 
40
89
  You can add configuration that applies to all your projects to `~/.vagrant.d/Vagrantfile`, eg:
@@ -46,7 +95,7 @@ You can add configuration that applies to all your projects to `~/.vagrant.d/Vag
46
95
  end
47
96
  end
48
97
 
49
- The ubuntu_mirror value can also be:
98
+ The mirror value can also be:
50
99
  * 'mirror' - Configures mirror: option to auto select from http://mirrors.ubuntu.com/mirrors.txt
51
100
  * 'internode' - an australian ISP (mine ;)
52
101
  * a country code - eg 'au', 'uk', 'us' etc
@@ -72,12 +121,8 @@ TODO: write the helper and then configure capistrano to use it ...
72
121
 
73
122
  TODO: Write usage instructions here
74
123
 
75
- Salt rules are copied into RAILS_ROOT/tmp/salt and pillar info into RAILS_ROOT/tmp/pillar by the `configure_salt` method.
76
- It also (re)creates `pillar/application.sls` based on `.ruby-version`, `config/database.yml` and `Gemfile` ehenever they change.
77
- The configuration files are also copied to `salt/railsapp/files/`.
78
-
79
- If you move `RAILS_ROOT/tmp/salt` and `RAILS_ROOT/tmp/pillar` into a RAILS_ROOT/salt directory then you can adjust the other files as desired.
80
- In that case only the `pillar/application.sls` and `salt/railsapp/files/*` files will be refreshed when they become stale (rather than all files).
124
+ This gem generates pillar and salt files in RAILS_ROOT/tmp/salt and RAILS_ROOT/tmp/pillar respectively from your application configuration files.
125
+ The files it generates are based on `.ruby-version`, `config/database.yml` and `Gemfile` as well
81
126
 
82
127
  ## Contributing
83
128
 
data/init.sh ADDED
@@ -0,0 +1,64 @@
1
+ #!/bin/sh
2
+
3
+ msg='OK: Vagrant has been setup: ready for vagrant up [--provider=digital_ocean]'
4
+
5
+ if which VirtualBox; then
6
+ echo Found Virtualbox
7
+ else
8
+ echo ACTION REQUIRED: Please install Virtualbox 4.2.18 or later from https://www.virtualbox.org/wiki/Downloads
9
+ msg='(PLEASE RERUN SCRIPT AFTERWARDS)'
10
+ fi
11
+
12
+ if which vagrant; then
13
+ echo Found vagrant
14
+ echo Checking vagrant plugins are installed ...
15
+
16
+ vagrant plugin list > /tmp/t$$
17
+ for plugin in deep_merge vagrant-digitalocean vagrant-vbguest # salted-rails
18
+ do
19
+ if grep $plugin < /tmp/t$$; then
20
+ vagrant plugin update $plugin
21
+ else
22
+ vagrant plugin install $plugin
23
+ fi
24
+ done
25
+
26
+ else
27
+ echo ACTION REQUIRED: Please install vagrant 1.3.4 or later from http://www.vagrantup.com/
28
+ msg='(PLEASE RERUN SCRIPT AFTERWARDS)'
29
+ fi
30
+
31
+ if [ -f Vagrantfile.example ]; then
32
+ if [ -f Vagrantfile ]; then
33
+ echo Found Vagrantfile '(previously copied from example)'
34
+ else
35
+ echo Copying Vagrantfile.example to Vagrantfile '(so you can customize it)'
36
+ cp Vagrantfile.example Vagrantfile
37
+ fi
38
+ else
39
+ echo ERROR: setup_vagrant Must be run in rails root directory '(Vagrantfile.example not found)'
40
+ msg='(PLEASE RERUN SCRIPT FROM CORRECT DIRECTORY)'
41
+ fi
42
+
43
+ mkdir -p $HOME/.vagrant.d
44
+
45
+ if [ -f "$HOME/.vagrant.d/Vagrantfile" ]; then
46
+ echo Found global Vagrantfile
47
+ else
48
+ echo "About to set up ~/.vagrant.d/Vagrantfile"
49
+ echo -n "Enter your digital ocean client key (defaul none): "
50
+ read client_id
51
+ echo -n "Enter your digital ocean API key (defaul none): "
52
+ read api_key
53
+ echo "
54
+ Vagrant.configure('2') do |config|
55
+ config.vm.provider :digital_ocean do |provider|
56
+ provider.client_id = '$client_id'
57
+ provider.api_key = '$api_key'
58
+ end
59
+ end
60
+ " > $HOME/.vagrant.d/Vagrantfile
61
+ fi
62
+ echo
63
+ echo "$msg"
64
+ exit 0
data/lib/salted-rails.rb CHANGED
@@ -1,8 +1,6 @@
1
- require "salted_rails_base"
2
- require "salted_rails/version"
1
+ require "salted-rails/version"
2
+ require "salted-rails/config"
3
+ require "salted-rails/vagrant_helper"
3
4
 
4
- class SaltedRails < SaltedRailsBase
5
- name "Salted Rails"
5
+ module SaltedRails
6
6
  end
7
-
8
-
@@ -0,0 +1,106 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ #
4
+
5
+ require 'erb'
6
+ require 'yaml'
7
+ require 'fileutils'
8
+ require 'salted-rails/helper_base'
9
+
10
+ module SaltedRails
11
+ class CapistranoHelper < HelperBase
12
+
13
+ def initialize(rails_root, logger = Log4r::Logger.new("salted_rails::capistrano_helper"))
14
+ super(rail_root, logger)
15
+ end
16
+
17
+ # def configure_vagrant(config)
18
+ # config.vm.box = 'UbuntuCloud_12.04_32bit'
19
+ # config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box'
20
+ # end
21
+ #
22
+ # def configure_ubuntu_mirror(config, mirror = 'mirror://mirrors.ubuntu.com/mirrors.txt')
23
+ # config.vm.provision "shell" do |s|
24
+ # s.path = @salt_root + 'salt/bin/change_mirror.sh'
25
+ # s.args = "'#{mirror}'"
26
+ # end
27
+ # end
28
+ #
29
+ # def configure_digital_ocean(config, private_key_path = '~/.ssh/id_rsa', disable_vagrant_sync = true)
30
+ # @logger.info 'Configuring digital ocean provider' if @logger
31
+ # @has_digital_ocean = 1
32
+ # config.vm.provider :digital_ocean do |provider, override|
33
+ # override.ssh.username = 'vagrant'
34
+ # override.vm.box = 'digital_ocean'
35
+ # override.vm.box_url = 'https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box'
36
+ # provider.image = 'Ubuntu 12.04 x32'
37
+ # provider.region = 'San Francisco 1'
38
+ # provider.ca_path = '/etc/ssl/certs/ca-certificates.crt' if File.exist?('/etc/ssl/certs/ca-certificates.crt')
39
+ # override.vm.synced_folder '.', '/vagrant', :disabled => true if disable_vagrant_sync
40
+ # override.ssh.private_key_path = private_key_path
41
+ # @private_key_name = 'Vagrant ' + private_key_path.sub(/~\//, '').sub(/\.ssh\//, '').sub(/^id_/, '').gsub(/\W+/, ' ')
42
+ # provider.ssh_key_name = @private_key_name if @private_key_name
43
+ # override.ssh.forward_agent = true
44
+ # end
45
+ # end
46
+ #
47
+ # def configure_salt(config)
48
+ # pillarize_application_configuration
49
+ # config.vm.synced_folder @salt_root + 'config/salt/', '/srv/salt/config/'
50
+ # config.vm.synced_folder @salt_root + 'config/pillar/', '/srv/pillar/config/'
51
+ # config.vm.synced_folder @salt_root + 'salt/', '/srv/salt/salted-rails/'
52
+ # config.vm.synced_folder @salt_root + 'pillar/', '/srv/pillar/salted-rails/'
53
+ # # Bootstrap salt
54
+ # ## config.vm.provision :shell, :inline => 'salt-call --version || wget -O - http://bootstrap.saltstack.org | sudo sh'
55
+ # # Provisioning #2: masterless highstate call
56
+ # config.vm.provision :salt do |salt|
57
+ # @logger.info 'Configuring salt provisioner' if @logger
58
+ # minion_file = @rails_root + 'config/salt/vagrant/minion'
59
+ # minion_file = @salt_root + 'salt/vagrant/minion' unless File.exists? minion_file
60
+ # salt.minion_config = minion_file
61
+ # salt.run_highstate = true
62
+ # salt.verbose = !! @logger
63
+ # end
64
+ # end
65
+ #
66
+ # def configure_ports(vm_config, port_offset=0)
67
+ # vm_config.vm.network :forwarded_port, :guest => 3000 + port_offset, :host => 3000, auto_correct: true
68
+ # [ 80, 443, 880 ].each do |port|
69
+ # vm_config.vm.network :forwarded_port, :guest => port, :host => 3000+port + port_offset, auto_correct: true
70
+ # end
71
+ # end
72
+ #
73
+ # def configure_gui(vm_config, memory = 1024)
74
+ # @gui = true
75
+ # configure_memory(memory)
76
+ # vm_config.vm.boot_mode == :gui
77
+ # vm_config.vm.provision :salt do |salt|
78
+ # minion_file = @rails_root + 'config/salt/vagrant/gui_minion'
79
+ # minion_file = @salt_root + 'salt/vagrant/gui_minion' unless File.exists? minion_file
80
+ # salt.minion_config = minion_file
81
+ # end
82
+ # end
83
+ #
84
+ # def configure_memory(memory = 1024)
85
+ # config.vm.provider :virtualbox do |vb|
86
+ # vb.customize ["modifyvm", :id, "--memory", memory]
87
+ # end
88
+ # config.vm.provider :digital_ocean do |provider, override|
89
+ # if memory >= 8000
90
+ # provider.size = '8GB'
91
+ # elsif memory >= 4000
92
+ # provider.size = '4GB'
93
+ # elsif memory >= 2000
94
+ # provider.size = '2GB'
95
+ # elsif memory >= 1000
96
+ # provider.size = '1GB'
97
+ # else
98
+ # provider.size = '512MB'
99
+ # end
100
+ # end
101
+ # end
102
+
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,14 @@
1
+ module SaltedRails
2
+ class CloudVbguestInstaller < VagrantVbguest::Installers::Ubuntu
3
+ def install(opts=nil, &block)
4
+ communicate.sudo("apt-get -y -q purge virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11", opts, &block)
5
+ @vb_uninstalled = true
6
+ super
7
+ end
8
+
9
+ def running?(opts=nil, &block)
10
+ return false if @vb_uninstalled
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,212 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ #
4
+
5
+ require 'log4r'
6
+
7
+ module SaltedRails
8
+ class Config
9
+
10
+ attr_accessor :private_key_path
11
+ attr_accessor :machine
12
+ attr_accessor :hostname
13
+ attr_accessor :domain
14
+ attr_accessor :rails_root
15
+ attr_accessor :salt_root
16
+ attr_accessor :mirror
17
+ attr_accessor :logger
18
+ attr_accessor :memory
19
+ attr_accessor :ports
20
+ attr_accessor :disable_vagrant_sync
21
+ attr_accessor :ca_path
22
+ attr_accessor :region
23
+ attr_accessor :forward_agent
24
+ attr_accessor :files
25
+ attr_accessor :databases
26
+ attr_accessor :roles
27
+ attr_accessor :gems
28
+ attr_accessor :ruby_version
29
+ attr_accessor :java_version
30
+ attr_accessor :php_version
31
+ attr_accessor :machines
32
+ attr_accessor :copy_from_home
33
+
34
+ def sanitize_dns_name(name)
35
+ dns_name = name.downcase.gsub(/[^-0-9a-z]+/,'-').sub(/^-+/, '').sub(/-+$/, '')
36
+ end
37
+
38
+ # pass vm.ui for the logger if you want debugging info
39
+ def initialize(rails_root, machine = 'default')
40
+ @logger = Log4r::Logger.new("vagrant::salted-rails")
41
+ @machine = machine
42
+ @rails_root = rails_root
43
+ @rails_root += '/' unless @rails_root =~ /\/$/
44
+ @salt_root = nil
45
+ # see salt/vagrant/top.sls for other roles
46
+ @roles = %w{ app web db }
47
+ @domain = nil
48
+ @private_key_path = nil
49
+ @mirror = nil
50
+ @memory = nil
51
+ @ports = [ 80, 443, 880, 3000 ]
52
+ @disable_vagrant_sync = true
53
+ @ca_path = nil
54
+ @region = nil
55
+ @forward_agent = true
56
+ @files = [ '.ruby-version', '.java-version', '.php-version', '.rvmrc', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) }
57
+ @copy_from_home = [ ]
58
+
59
+ ENV['REMOTE_MACHINE'] = 'true'
60
+ database_file = @rails_root + 'config/database.yml'
61
+ @databases = YAML.load(ERB.new(IO.read(database_file)).result) rescue { }
62
+ ENV['REMOTE_MACHINE'] = nil
63
+
64
+ @gems = { }
65
+ if File.exists? @rails_root + 'Gemfile'
66
+ File.foreach(@rails_root + 'Gemfile') do |line|
67
+ if line =~ /^\s*gem\s*['"]([^'"]+)['"][,\s]*(['"]([^'"]+)['"])?/
68
+ gem = $1
69
+ version = $3.to_s
70
+ version = true if version == '' or version !~ /\d/
71
+ @gems[gem] = version
72
+ end
73
+ end
74
+ end
75
+ @databases.each do |key, details|
76
+ @gems[details['adapter']] = true
77
+ end
78
+
79
+ @ruby_version = nil
80
+ @java_version = nil
81
+ @php_version = nil
82
+
83
+ @machines = [ ]
84
+ @hostname = nil
85
+ end
86
+
87
+ def gui?
88
+ @roles.include? 'gui'
89
+ end
90
+
91
+ def normalize
92
+ unless @memory
93
+ @memory = 512
94
+ {
95
+ 'gui' => 1536,
96
+ 'teamcity' => 1536,
97
+ 'cruisecontrolrb' => 512
98
+ }.each do |role, extra|
99
+ @memory += extra if @roles.include?(role)
100
+ end
101
+ end
102
+ unless @domain
103
+ if @hostname
104
+ @domain = @hostname.sub(/^[^.]*\.?/, '')
105
+ else
106
+ @domain = sanitize_dns_name(File.basename(File.expand_path(@rails_root).sub(/\/$/, '').sub(/\/(app|site|web|www|website)\d*$/, ''))) + '.test'
107
+ @domain = 'railsapp.test' if @domain == '.test'
108
+ end
109
+ end
110
+ if @hostname.nil? or @hostname == ''
111
+ if @machine == 'default'
112
+ @hostname = @domain
113
+ else
114
+ @hostname = sanitize_dns_name(@machine.to_s)
115
+ if @hostname == ''
116
+ @hostname = @domain
117
+ else
118
+ @hostname <<= '.' + @domain
119
+ end
120
+ end
121
+ end
122
+ @ruby_version ||= File.open(@rails_root + '.ruby-version', 'r') do |f_in|
123
+ f_in.gets.gsub(/\s/,'')
124
+ end rescue nil
125
+ @ruby_version ||= File.open(@rails_root + '.rvmrc', 'r') do |f_in|
126
+ while !ruby_version && (line = f_in.gets)
127
+ ruby_version = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/
128
+ end
129
+ end rescue nil
130
+ @ruby_version ||= '1.9.3'
131
+
132
+ @java_version ||= File.open(@rails_root + '.java-version', 'r') do |f_in|
133
+ f_in.gets.gsub(/\s/,'')
134
+ end rescue nil
135
+
136
+ @php_version ||= File.open(@rails_root + '.php-version', 'r') do |f_in|
137
+ f_in.gets.gsub(/\s/,'')
138
+ end rescue nil
139
+
140
+ @private_key_path ||= '~/.ssh/id_rsa'
141
+ @mirror ||= 'auto'
142
+ @salt_root ||= File.dirname(__FILE__) + '/../../'
143
+ @ca_path ||= '/etc/ssl/certs/ca-certificates.crt'
144
+ @ca_path = nil unless File.exist?(@ca_path)
145
+ @region ||= 'San Francisco 1'
146
+
147
+ @machines.each {|m| m.normalize}
148
+
149
+ {
150
+ 'teamcity' => 8111,
151
+ 'cruisecontrolrb' => 3333
152
+ }.each do |role, port|
153
+ @ports << port if @roles.include?(role) and not @ports.include?(port)
154
+ end
155
+
156
+ end
157
+
158
+ def define(machine, &block)
159
+ obj = self.clone
160
+ obj.machine = machine
161
+ obj.machines = [ ]
162
+ obj.logger = @logger
163
+ @machines << obj
164
+ yield(obj) if block_given?
165
+ end
166
+
167
+ # Clone
168
+ def clone
169
+ obj = self.dup
170
+ obj.roles = @roles.dup
171
+ obj.ports = @ports.dup
172
+ obj.files = @files.dup
173
+ obj.copy_from_home = @copy_from_home.dup
174
+ obj.databases = @databases.dup
175
+ obj.gems = @gems.dup
176
+ obj
177
+ end
178
+
179
+ def to_hash
180
+ {
181
+ 'domain' => @domain,
182
+ 'mirror' => @mirror,
183
+ 'machine' => @machine,
184
+ 'hostname' => @hostname,
185
+ 'memory' => @memory,
186
+ 'disable_vagrant_sync' => @disable_vagrant_sync,
187
+ 'region' => @region,
188
+ 'forward_agent' => @forward_agent,
189
+ 'files' => @files,
190
+ 'databases' => @databases,
191
+ 'gems' => @gems,
192
+ 'ruby_version' => @ruby_version,
193
+ 'java_version' => @java_version,
194
+ 'php_version' => @php_version,
195
+ 'roles' => @roles
196
+ }
197
+ end
198
+
199
+ def to_yaml
200
+ normalize
201
+ self.to_hash.to_yaml
202
+ end
203
+
204
+ def configure_vagrant(config)
205
+ require 'salted-rails/vagrant_helper'
206
+ normalize
207
+ helper = SaltedRails::VagrantHelper.new(self)
208
+ helper.configure_vagrant(config)
209
+ end
210
+
211
+ end
212
+ end