lib/salted-rails/config.rb in salted-rails-0.0.6 vs lib/salted-rails/config.rb in salted-rails-0.0.7

- old
+ new

@@ -5,33 +5,36 @@ require 'log4r' module SaltedRails class Config - attr_accessor :private_key_path - attr_accessor :machine - attr_accessor :hostname + attr_accessor :box + attr_accessor :ca_path + attr_accessor :copy_from_home + attr_accessor :admin_password + attr_accessor :web_password + attr_accessor :databases attr_accessor :domain - attr_accessor :rails_root - attr_accessor :salt_root - attr_accessor :mirror + attr_accessor :files + attr_accessor :forward_agent + attr_accessor :gems + attr_accessor :hostname attr_accessor :logger + attr_accessor :machine + attr_accessor :machines attr_accessor :memory + attr_accessor :mirror + attr_accessor :packages attr_accessor :ports - attr_accessor :disable_vagrant_sync - attr_accessor :ca_path + attr_accessor :mapped_ports + attr_accessor :private_key_path + attr_accessor :rails_root attr_accessor :region - attr_accessor :forward_agent - attr_accessor :files - attr_accessor :databases attr_accessor :roles - attr_accessor :gems - attr_accessor :ruby_version - attr_accessor :java_version - attr_accessor :php_version - attr_accessor :machines - attr_accessor :copy_from_home + attr_accessor :salt_root + attr_accessor :sync_vagrant + attr_accessor :versions def sanitize_dns_name(name) dns_name = name.downcase.gsub(/[^-0-9a-z]+/,'-').sub(/^-+/, '').sub(/-+$/, '') end @@ -43,19 +46,24 @@ @rails_root += '/' unless @rails_root =~ /\/$/ @salt_root = nil # see salt/vagrant/top.sls for other roles @roles = %w{ app web db } @domain = nil + @admin_password = nil + @web_password = nil @private_key_path = nil @mirror = nil @memory = nil @ports = [ 80, 443, 880, 3000 ] - @disable_vagrant_sync = true + @mapped_ports = { } + @sync_vagrant = nil + @box = nil @ca_path = nil @region = nil @forward_agent = true - @files = [ '.ruby-version', '.java-version', '.php-version', '.rvmrc', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) } + @files = [ '.ruby-version', '.java-version', '.php-version', 'config/database.yml', 'Gemfile', 'Gemfile.lock' ].select{ |f| File.exist?(@rails_root + f) } + @packages = nil @copy_from_home = [ ] ENV['REMOTE_MACHINE'] = 'true' database_file = @rails_root + 'config/database.yml' @databases = YAML.load(ERB.new(IO.read(database_file)).result) rescue { } @@ -71,44 +79,65 @@ @gems[gem] = version end end end @databases.each do |key, details| - @gems[details['adapter']] = true + @gems[details['adapter']] ||= true end - @ruby_version = nil - @java_version = nil - @php_version = nil + @roles << 'mysql' if @gems.include?('mysql') or @gems.include?('mysql2') + @versions= { } + @machines = [ ] @hostname = nil end def gui? @roles.include? 'gui' end def normalize - unless @memory + @versions['mysql'] ||= '5.5' if @roles.include?('mysql') + @versions['teamcity'] ||= '8.0.4' if @roles.include?('teamcity') + @versions['rubymine'] ||= '5.4.3' if @roles.include?('rubymine') + @roles << 'gui' if @roles.include?('rubymine') and not @roles.include?('gui') + + %w{ ruby php java }.each do |lang| + version = File.open(@rails_root + ".#{lang}-version", 'r') do |f_in| + f_in.gets.gsub(/\s/,'') + end rescue nil + @versions[lang] ||= version if version + end + unless @versions.include?('ruby') + File.open(@rails_root + '.rvmrc', 'r') do |f_in| + while (line = f_in.gets) and not @versions.include('ruby') + @versions['ruby'] = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/ + end + end rescue nil + end + + if @memory.nil? @memory = 512 { 'gui' => 1536, 'teamcity' => 1536, 'cruisecontrolrb' => 512 }.each do |role, extra| @memory += extra if @roles.include?(role) end end - unless @domain + + if @domain.nil? if @hostname @domain = @hostname.sub(/^[^.]*\.?/, '') else @domain = sanitize_dns_name(File.basename(File.expand_path(@rails_root).sub(/\/$/, '').sub(/\/(app|site|web|www|website)\d*$/, ''))) + '.test' @domain = 'railsapp.test' if @domain == '.test' end end + if @hostname.nil? or @hostname == '' if @machine == 'default' @hostname = @domain else @hostname = sanitize_dns_name(@machine.to_s) @@ -117,44 +146,29 @@ else @hostname <<= '.' + @domain end end end - @ruby_version ||= File.open(@rails_root + '.ruby-version', 'r') do |f_in| - f_in.gets.gsub(/\s/,'') - end rescue nil - @ruby_version ||= File.open(@rails_root + '.rvmrc', 'r') do |f_in| - while !ruby_version && (line = f_in.gets) - ruby_version = $1 if line =~ /^\s*environment_id=['"]([^"'@]+)/ - end - end rescue nil - @ruby_version ||= '1.9.3' - @java_version ||= File.open(@rails_root + '.java-version', 'r') do |f_in| - f_in.gets.gsub(/\s/,'') - end rescue nil - - @php_version ||= File.open(@rails_root + '.php-version', 'r') do |f_in| - f_in.gets.gsub(/\s/,'') - end rescue nil - @private_key_path ||= '~/.ssh/id_rsa' @mirror ||= 'auto' @salt_root ||= File.dirname(__FILE__) + '/../../' @ca_path ||= '/etc/ssl/certs/ca-certificates.crt' + @box ||= 'preciseCloud32' @ca_path = nil unless File.exist?(@ca_path) @region ||= 'San Francisco 1' - @machines.each {|m| m.normalize} - { 'teamcity' => 8111, 'cruisecontrolrb' => 3333 }.each do |role, port| @ports << port if @roles.include?(role) and not @ports.include?(port) end + @sync_vagrant = true if @sync_vagrant.nil? + + @machines.each {|m| m.normalize} end def define(machine, &block) obj = self.clone obj.machine = machine @@ -176,24 +190,26 @@ obj end def to_hash { + 'admin_password' => @admin_password, + 'databases' => @databases, + 'disable_vagrant_sync' => @disable_vagrant_sync, 'domain' => @domain, - 'mirror' => @mirror, - 'machine' => @machine, + 'files' => @files, + 'forward_agent' => @forward_agent, + 'gems' => @gems, 'hostname' => @hostname, + 'machine' => @machine, + 'mapped_ports' => @mapped_ports, 'memory' => @memory, - 'disable_vagrant_sync' => @disable_vagrant_sync, + 'mirror' => @mirror, + 'ports' => @ports, 'region' => @region, - 'forward_agent' => @forward_agent, - 'files' => @files, - 'databases' => @databases, - 'gems' => @gems, - 'ruby_version' => @ruby_version, - 'java_version' => @java_version, - 'php_version' => @php_version, - 'roles' => @roles + 'roles' => @roles, + 'user_password' => @user_password, + 'versions' => @versions } end def to_yaml normalize