Class: TddDeploy::Configurator
- Defined in:
- lib/tdd_deploy/configurator.rb
Overview
TddDeployConfigurator
NOTE: you generally do NOT use the TddDeploy::Configurator class directly. You will seed your configuration files using the supplied ‘rake’ task; edit, modify, delete, spindle, fold and mutilate as you please; and then, click the ‘Run configurator’ link in the server page.
TddDeploy::Configurator is used to create site/host specific configuration files for sites. The files are defined by templates in subdirectories of the ‘site-erb’ directory.
templates are installed in your app’s ‘lib/tdd_deploy/site-erb’ directory. There are three subdirectories - one for each server class: balance_hosts, db_hosts, and web_hosts.
Templates actually reside in subdirectories which correspond to installation directories on the deployment hosts. Thus, templates for the ‘config’ directory for the ‘balance_hosts’ are in ‘lib/tdd_deploy/site-erb/balance_hosts/config’
I put other config files and executables in the directory ‘site’. At present these are include files for ‘nginx’ and ‘monit’.
At present there are templates in ‘site-erb/config’ and ‘site-erb/site’. Rendered files are written to corresponding subdirectories of ‘tdd_deploy_configs’ in your application.
It’s your problem to deal with file permission issues.
Constant Summary
Constants included from Assertions
Assertions::GROUP_ELT_TAG, Assertions::HEADER_ELT_TAG, Assertions::RESULT_ELT_TAG
Constants included from Environ
Instance Method Summary collapse
-
#make_configuration_files ⇒ Object
install - reads all the templates in gem-home/site-erb, renders them using the current environment context, and writes the renderings to the appropriate files in app/sites and app/config.
Methods inherited from Base
Methods included from DeployTestMethods
#deploy_test_file_exists_on_hosts_as, #deploy_test_on_a_host_as, #deploy_test_on_hosts_as, #deploy_test_process_running_on_hosts_as
Methods included from RunMethods
#ping_host, #run_locally, #run_on_a_host_as, #run_on_all_hosts, #run_on_all_hosts_as, #run_on_hosts_as
Methods included from Assertions
#assert, #assert_equal, #assert_match, #assert_nil, #assert_not_nil, #assert_raises, #fail, #failure_count, #failure_messages, #formatted_test_results, #pass, #refute, #refute_equal, #refute_nil, #remove_failed_tests, #reset_tests, #test_count, #test_messages, #test_results, #total_failures, #total_tests
Methods included from CopyMethods
#append_dir_to_remote_hosts_as, #append_file_to_remote_file_as, #append_file_to_remote_hosts_as, #append_string_to_remote_file_as, #append_string_to_remote_file_on_hosts_as, #copy_dir_to_remote_hosts_as, #copy_file_to_remote_as, #copy_file_to_remote_hosts_as, #copy_string_to_remote_file_as, #copy_string_to_remote_file_on_hosts_as, #mkdir_on_remote_as
Methods included from Environ
#capfile, #clear_env, #env_defaults, #env_desc, #env_hash, #env_hash=, #env_types, #hosts, #hosts=, #list_to_str, #migration_hosts, #rationalize_host_list, #read_env, #reset_env, #save_env, #set_env, #str_to_list
Constructor Details
This class inherits a constructor from TddDeploy::Base
Instance Method Details
#make_configuration_files ⇒ Object
install - reads all the templates in gem-home/site-erb, renders them using the
current environment context, and writes the renderings to the appropriate
files in app/sites and app/config
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tdd_deploy/configurator.rb', line 37 def make_configuration_files # create local directory for output files tdd_deploy_configs = File.join Dir.pwd, 'tdd_deploy_configs' Dir.mkdir(tdd_deploy_configs) unless File.exists? tdd_deploy_configs ['app_hosts', 'balance_hosts', 'db_hosts', 'web_hosts'].each do |host_dir| host_path = File.join(tdd_deploy_configs, host_dir) Dir.mkdir(host_path) unless File.exists? host_path ['config', 'site'].each do |subdir| subdir_path = File.join(host_path, subdir) Dir.mkdir(subdir_path) unless File.exists? subdir_path end end # instantiate all templates and write output to tdd_deploy_configs erb_dir = File.join('lib', 'tdd_deploy', 'site-erb') # erb_dir = File.expand_path('../site-erb', __FILE__) Dir.new(erb_dir).each do |host_dir_fname| next if host_dir_fname[0] == '.' host_dir_path = File.join(erb_dir, host_dir_fname) Dir.new(host_dir_path).each do |subdir| next if subdir[0] == '.' subdir_path = File.join(host_dir_path, subdir) Dir.new(subdir_path).each do |fname| file_path = File.join(subdir_path, fname) next unless fname =~ /\.erb$/ && File.exists?(file_path) f = File.new(file_path) # '>' removes new-lines from lines ending in %> # template = ERB.new f.read, nil, '>' # '>' removes new-lines from lines starting with <% and ending in %> template = ERB.new f.read, nil, '<>' f.close file_content = template.result(binding) out_fname = File.basename(fname, '.erb') Dir.mkdir(subdir_path) unless File.exists? subdir_path out_path = File.join(tdd_deploy_configs, host_dir_fname, subdir, out_fname) f = File.new(out_path, "w") f.write template.result(binding) f.close # make files in 'app/site' executable File.chmod 0755, out_path if subdir == 'site' end end end end |