Class: FromScratch
- Inherits:
-
Object
- Object
- FromScratch
- Defined in:
- lib/from-scratch.rb,
lib/from-scratch/version.rb
Constant Summary collapse
- DEFAULTS =
{ ruby_installer: 'rvm' }
- VERSION =
"0.6.0"
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #generate_values ⇒ Object
- #get_host_and_app_name ⇒ Object
-
#initialize ⇒ FromScratch
constructor
A new instance of FromScratch.
- #parse_options ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize ⇒ FromScratch
Returns a new instance of FromScratch.
12 13 14 |
# File 'lib/from-scratch.rb', line 12 def initialize @options = OpenStruct.new DEFAULTS end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/from-scratch.rb', line 10 def @options end |
Instance Method Details
#generate_values ⇒ Object
63 64 65 66 67 |
# File 'lib/from-scratch.rb', line 63 def generate_values @options.ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip @options.postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip @options.postgresql_user_password = SecureRandom.base64(16) end |
#get_host_and_app_name ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/from-scratch.rb', line 38 def get_host_and_app_name @options.app_name, @options.host = ARGV.select { |x| !(x =~ /^\-/) } unless @options.app_name && @options.host raise ArgumentError, 'You should specify APP_NAME and HOST. Use --help for information.' end end |
#parse_options ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/from-scratch.rb', line 46 def opt_parser = OptionParser.new do |args| args. = "Usage: scratchify your_app_name your.host.com [options]" args.on '--rbenv', 'Use RBENV instead of RVM' do @options.ruby_installer = 'rbenv' end args.on '-h', '--help', 'Prints this help' do puts args exit end end opt_parser.parse! end |
#run! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/from-scratch.rb', line 16 def run! get_host_and_app_name generate_values { node: ['nodes', @options.host], user: ['data_bags/users', 'deploy'] }.each do |from, to| FileUtils.mkdir_p File.("../../tmp/#{to[0]}", __FILE__) File.open(File.("../../tmp/#{to.join('/')}.json", __FILE__), 'w') do |f| f.write ERB.new(File.open(File.("../../templates/#{from}.json.erb", __FILE__)).read).result(binding) end end Dir.chdir(File.('../..', __FILE__)) do system "knife solo bootstrap root@#{@options.host} -c ./.chef/knife.rb" system "knife solo clean root@#{@options.host} -c ./.chef/knife.rb" end FileUtils.rm_rf [File.('../../tmp', __FILE__)] end |