class Roro::CLI
Public Class Methods
roro_environments()
click to toggle source
# File lib/roro/cli.rb, line 30 def self.roro_environments %w(development production test staging ci) end
source_root()
click to toggle source
# File lib/roro/cli.rb, line 18 def self.source_root File.dirname(__FILE__) + '/templates' end
story_root()
click to toggle source
# File lib/roro/cli.rb, line 22 def self.story_root File.dirname(__FILE__) + '/stories' end
test_fixture_root()
click to toggle source
# File lib/roro/cli.rb, line 26 def self.test_fixture_root File.dirname(__FILE__) + '/test/fixtures' end
Private Class Methods
desc(*args)
click to toggle source
# File lib/roro/cli/rollon.rb, line 14 def desc(*args) orig_desc(*args) shared_options! end
Also aliased as: orig_desc
Public Instance Methods
check_for_keys(environments)
click to toggle source
# File lib/roro/cli/generate/generate_obfuscated.rb, line 24 def check_for_keys(environments) environments.each do |e| unless File.exist?("roro/keys/#{e}.key") msg = "No #{e} key file at roro/keys/{e}.key. Please generate one." raise Roro::Error.new(msg) end end end
check_for_obfuscatable(environments)
click to toggle source
# File lib/roro/cli/generate/generate_obfuscated.rb, line 16 def check_for_obfuscatable(environments) if environments.empty? msg = "No .env files matching the pattern roro/**/*.env'. Please create one." raise Roro::Error.new(msg) end end
config_std_out_true()
click to toggle source
# File lib/roro/cli/rollon/rails/base/insertions.rb, line 8 def config_std_out_true file = 'config/boot.rb' line = "$stdout.sync = true\n\n" prepend_to_file(file, line, force: true) end
configure_database()
click to toggle source
# File lib/roro/cli/rollon/rails/database.rb, line 7 def configure_database database = @config.intentions[:configure_database] case database when 'p' @config.env[:database_vendor] = 'postgresql' configure_for_pg when 'm' @config.env[:database_vendor] = 'mysql' configure_for_mysql end %w(development production test staging ci).each do |environment| src = 'rails/dotenv/web.env.tt' dest = "roro/containers/app/#{environment}.env" template src, dest, @config.env end end
configure_for_mysql()
click to toggle source
# File lib/roro/cli/rollon/rails/database/with_mysql.rb, line 7 def configure_for_mysql insert_db_gem('mysql2') copy_file 'rails/config/database.mysql.yml', 'config/database.yml', force: true config = @config.env.clone %w(development production test staging ci).each do |environment| config[:rails_env] = environment source = 'rails/dotenv/database.mysql.env.tt' target = "roro/containers/database/#{environment}.env" template( source, target, config ) end end
configure_for_pg()
click to toggle source
# File lib/roro/cli/rollon/rails/database/with_postgresql.rb, line 7 def configure_for_pg copy_file 'rails/config/database.pg.yml', 'config/database.yml', force: true config = @config.env.clone %w(development production test staging ci).each do |environment| config[:rails_env] = environment source = 'rails/dotenv/database.pg.env.tt' target = "roro/containers/database/#{environment}.env" template( source, target, config ) end end
configure_for_rollon(aroptions=nil)
click to toggle source
# File lib/roro/cli/rollon.rb, line 83 def configure_for_rollon(aroptions=nil) @config ||= Roro::Configuration.new(options) end
congratulations(story=nil)
click to toggle source
# File lib/roro/cli/rollon.rb, line 105 def congratulations(story=nil) ( @config.story[:rollon]) if @config.structure[:greenfield] usecase = 'greenfielded a new ' else usecase = 'rolled your existing ' end array = ["You've successfully "] array << usecase congrats = array.join("") puts congrats end
copy_dockerignore()
click to toggle source
# File lib/roro/cli/rollon/rails/base/insertions.rb, line 14 def copy_dockerignore copy_file 'base/.dockerignore', '.dockerignore' end
generate_config_story()
click to toggle source
# File lib/roro/cli/rollon.rb, line 137 def generate_config_story roro_story = { story: @config.story, env_vars: @config.env, intentions: @config.intentions } create_file ".roro_story.yml", roro_story.to_yaml end
generate_exposed(*environments)
click to toggle source
# File lib/roro/cli/generate/generate_exposed.rb, line 8 def generate_exposed(*environments) Roro::Crypto.expose(environments, './roro', '.env.enc') end
generate_keys(*environments)
click to toggle source
# File lib/roro/cli/generate/generate_keys.rb, line 10 def generate_keys(*environments) Roro::Crypto.generate_keys(environments, './roro', '.env') end
generate_obfuscated(*environments)
click to toggle source
# File lib/roro/cli/generate/generate_obfuscated.rb, line 10 def generate_obfuscated(*environments) Roro::Crypto.obfuscate(environments, './roro', '.env') end
generate_story()
click to toggle source
# File lib/roro/cli/generate/generate_story.rb, line 7 def generate_story @config ||= Roro::Configuration.new(options) # configuration = { # env_vars: @config.env.keys, # intentions: @config.intentions, # story: @config.structure['story'] # } # create_file ".roro_configurator.yml", @config.env.to_yaml end
gitignore_sensitive_files()
click to toggle source
# File lib/roro/cli/rollon/rails/base/insertions.rb, line 18 def gitignore_sensitive_files append_to_file ".gitignore", "\nroro/**/*.env\nroro/**/*.key" append_to_file ".gitignore", "\nroro/**/*.env\nroro/**/*.key" append_to_file ".gitignore", "\n*kubeconfig.yaml" append_to_file ".gitignore", "\n*kubeconfig.yml" append_to_file ".gitignore", "\n*.roro_configurator.yml" end
greenfield(args={})
click to toggle source
# File lib/roro/cli/rollon.rb, line 32 def greenfield(args={}) args[:greenfield] = :greenfield rollon(args) end
greenfield_actions()
click to toggle source
# File lib/roro/cli/rollon.rb, line 95 def greenfield_actions return unless @config.structure[:greenfield_actions] @config.structure[:greenfield_actions].each {|a| eval a } end
greenfield_commands()
click to toggle source
# File lib/roro/cli/rollon.rb, line 100 def greenfield_commands return unless @config.structure[:greenfield_actions] @config.structure[:greenfield_commands].each {|a| eval a } end
greenfield_rails()
click to toggle source
# File lib/roro/cli/greenfield/rails.rb, line 10 def greenfield_rails greenfield( { story: :rails } ) end
greenfield_rails_kubernetes(args={})
click to toggle source
# File lib/roro/cli/rollon.rb, line 70 def greenfield_rails_kubernetes(args={}) story = { rails: [ { database: :postgresql }, { kubernetes: :postgresql }, { ci_cd: :circleci} ] } rollon( { story: story } ) end
insert_db_gem(gem)
click to toggle source
# File lib/roro/cli/rollon/rails/base/insert_gems.rb, line 12 def insert_db_gem(gem) gems = %w(sqlite pg mysql2) gems.each { |g| gsub_file('Gemfile', /.*#{g}.*/, '')} insert_into_file 'Gemfile', "gem '#{gem}'\n\n", before: "group :development, :test" end
insert_hfci_gem_into_gemfile()
click to toggle source
# File lib/roro/cli/rollon/rails/base/insert_gems.rb, line 18 def insert_hfci_gem_into_gemfile insert_into_file 'Gemfile', "gem 'handsome_fencer-test'\n\n", after: "group :development, :test do" end
insert_roro_gem_into_gemfile()
click to toggle source
# File lib/roro/cli/rollon/rails/base/insert_gems.rb, line 8 def insert_roro_gem_into_gemfile insert_into_file 'Gemfile', "gem 'roro'\n\n", before: "group :development, :test do" end
manifest_actions()
click to toggle source
# File lib/roro/cli/rollon.rb, line 87 def manifest_actions @config.structure[:actions].each {|a| eval a } end
manifest_intentions()
click to toggle source
# File lib/roro/cli/rollon.rb, line 91 def manifest_intentions @config.intentions.each {|k, v| eval(k.to_s) if v.eql?('y') } end
rollon(args={})
click to toggle source
# File lib/roro/cli/rollon.rb, line 21 def rollon(args={}) @config ||= Roro::Configuration.new(args, options) greenfield_actions greenfield_commands manifest_actions manifest_intentions congratulations startup_commands end
rollon_rails(args={})
click to toggle source
# File lib/roro/cli/rollon.rb, line 49 def rollon_rails(args={}) rollon( { story: :rails } ) end
rollon_rails_kubernetes(args={})
click to toggle source
# File lib/roro/cli/rollon.rb, line 56 def rollon_rails_kubernetes(args={}) story = { rails: [ { database: :postgresql }, { kubernetes: :postgresql }, { ci_cd: :circleci} ] } rollon( { story: story } ) end
rollon_ruby_gem_with_ci_cd(*args)
click to toggle source
# File lib/roro/cli/rollon/ruby_gem/with_ci_cd.rb, line 7 def rollon_ruby_gem_with_ci_cd(*args) ruby_gem_with_ci_cd(*args) configure_for_rollon end
ruby_gem_with_ci_cd(*args)
click to toggle source
# File lib/roro/cli/rollon/ruby_gem/with_ci_cd.rb, line 13 def ruby_gem_with_ci_cd(*args) answer = ask("\nYou can add your rubygems api key in\n\t './roro/containers/ruby_gem/ci.env' \n\nlater, or we'll try to add it here:", default: '') rubygems_api_key = (answer.eql?("") ? 'some-key' : answer) @config.env[:rubygems_api_key] = rubygems_api_key @config.env[:rubies] = [] 3.times do |index| newruby = @config.env[:ruby_version].gsub('.', '').to_i - index @config.env[:rubies] << newruby.to_s.split('').join('.') end directory 'ruby_gem/roro', './roro', @config.env directory 'ruby_gem/.circleci', './.circleci', @config.env copy_file 'ruby_gem/docker-compose.yml', './docker-compose.yml' @config.env[:rubies].each do |ruby| file = '.circleci/config.yml' spacer = "\n - run: " rv = "RUBY_VERSION=#{ruby} docker-compose " build = "build ruby_gem" up = "up -d --force-recreate ruby_gem" run_tests = "run ruby_gem bundle exec rake test" append_to_file file, spacer + rv + run_tests, after: "- placeholder" append_to_file file, spacer + rv + up, after: "- placeholder" append_to_file file, spacer + rv + build, after: "- placeholder" end gsub_file '.circleci/config.yml', "- placeholder", "- checkout" append_to_file ".gitignore", "\nGemfile.lock" gitignore_sensitive_files end
startup_commands()
click to toggle source
# File lib/roro/cli/rollon.rb, line 118 def startup_commands congratulations( @config.story[:rollon]) cmd = @config.structure[:startup] commands = cmd[:commands] question = [] question << "\n\n You can start your app up with some combination of these commands:\n" commands.each { |c| question << "\t#{c}"} question << "\nOr if you'd like Roro to try and do it for you:" question = question.join("\n") if ask(question, default: 'y', limited_to: ['y', 'n']).eql?("y") commands.each {|a| system(a) } puts "\n\n#{cmd[:success]}\n\n" end end
yaml_from_template(file)
click to toggle source
# File lib/roro/cli/rollon.rb, line 133 def yaml_from_template(file) File.read(find_in_source_paths(file)) end