Class: FromScratch
- Inherits:
-
Object
- Object
- FromScratch
- Defined in:
- lib/from-scratch.rb,
lib/from-scratch/version.rb
Constant Summary collapse
- DEFAULTS =
{ ruby_installer: 'rvm', ruby_version: '2.2.4' }
- VERSION =
"0.7.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 = 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 end |
Instance Method Details
#generate_values ⇒ Object
67 68 69 70 71 |
# File 'lib/from-scratch.rb', line 67 def generate_values .ssh_pub_key = `cat ~/.ssh/id_rsa.pub`.strip .postgresql_admin_password = `echo -n '#{SecureRandom.base64(16)}''postgres' | openssl md5 | sed -e 's/.* /md5/'`.strip .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 .app_name, .host = ARGV.select { |x| !(x =~ /^\-/) } unless .app_name && .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 62 63 64 65 |
# 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 .ruby_installer = 'rbenv' end args.on '--ruby [VERSION]', "Choose specific ruby version instead of latest MRI" do |ruby_version| .ruby_version = ruby_version 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', .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 |