Module: Roro::Configurators::Eligibility
- Defined in:
- lib/roro/configurators/eligibility.rb
Instance Method Summary collapse
- #artifacts? ⇒ Boolean
- #confirm_dependencies ⇒ Object
- #confirm_dependency(options) ⇒ Object
- #confirm_directory_app ⇒ Object
- #confirm_directory_empty ⇒ Object
- #handle_roro_artifacts ⇒ Object
- #screen_target_directory ⇒ Object
Instance Method Details
#artifacts? ⇒ Boolean
36 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 |
# File 'lib/roro/configurators/eligibility.rb', line 36 def artifacts? @appname = @env[:main_app_name] @artifacts = {} hash = { containers: { list: "docker ps --filter name=#{@appname}\ -a", remove: ' -q | xargs docker stop | xargs docker rm -f' }, volumes: { list: "docker volume ls --filter name=#{@appname}*", remove: ' -q | xargs docker volume rm -f' }, networks: { list: "docker network ls --filter name=#{@appname}", remove: ' -q | xargs docker network rm' }, images: { list: "docker image ls #{@appname}*", remove: ' -q | xargs docker rmi -f' } } hash.each do |k, v| check = IO.popen("#{v[:list]} -q").count.positive? @artifacts[k] = v if check end true if @artifacts.empty? end |
#confirm_dependencies ⇒ Object
110 111 112 113 114 |
# File 'lib/roro/configurators/eligibility.rb', line 110 def confirm_dependencies dependencies.each do |dependency| confirm_dependency(dependency) end end |
#confirm_dependency(options) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/roro/configurators/eligibility.rb', line 91 def confirm_dependency() msg = [] msg << '' msg << delineator msg << "It looks like #{[:warning]}. The following bash command returns false:" msg << "\t$ #{[:system_query]}" msg << 'Try this:' msg << ("\t#{[:suggestion]}") msg << delineator conditional = [:conditional] ? eval([:conditional]) : system([:system_query]) query = [:system_query] if conditional == false raise Roro::Error, msg.join("\n\n") else true end end |
#confirm_directory_app ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/roro/configurators/eligibility.rb', line 13 def confirm_directory_app confirm_dependency({ system_query: 'ls -A', warning: "This is an empty directory. You can generate a new and fully dockerized Rails backend using the 'omakase' command here here but if you want to containerize an existing backend -- which is what the 'rollon' command is for -- you'll need to navigate to a directory with an backend we can roll onto.", suggestion: '$ roro omakase', conditional: "!Dir.glob('*').empty?" }) end |
#confirm_directory_empty ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/roro/configurators/eligibility.rb', line 26 def confirm_directory_empty confirm = confirm_dependency({ system_query: 'ls -A', warning: 'this is not an empty directory. Roro will not omakase a new Rails backend unless either a) the current directory is empty or b) you run omakase with the --force flag', suggestion: '$ roro omakase --force', conditional: "Dir.glob('*').empty?" # || (Dir.glob('*').size.eql?(1) && Dir.glob('roro_configurator.yml'))" }) confirm || true end |
#handle_roro_artifacts ⇒ Object
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 |
# File 'lib/roro/configurators/eligibility.rb', line 64 def handle_roro_artifacts return if artifacts? question = [ "\n\nThis machine has some docker artifacts which may clash with ", "RoRo moving forward. You can verify their existence with:\n" ] @artifacts.each { |_k, v| question << "\t$ #{v[:list]}" } question << "\nYou can remove these artifacts with something like:\n" @artifacts.each { |_k, v| question << "\t$ #{v[:list]} #{v[:remove]}" } question << "\nWould you like RoRo to attempt to remove them for you?" choices = { 'y' => 'Yes', 'n' => 'No' } choices.each { |k, v| question << "(#{k}) #{v}" } prompt = question.join answer = ask(prompt, default: 'y', limited_to: choices.keys) if answer.eql?('y') @artifacts.each do |k, v| puts "Attempting to remove #{k}" system(v[:list] + v[:remove]) end end end |
#screen_target_directory ⇒ Object
8 9 10 11 |
# File 'lib/roro/configurators/eligibility.rb', line 8 def screen_target_directory @structure[:greenfield] ? confirm_directory_empty : confirm_directory_app handle_roro_artifacts end |