Class: Bookbinder::CfCommandRunner
- Inherits:
-
Object
- Object
- Bookbinder::CfCommandRunner
- Defined in:
- lib/bookbinder/cf_command_runner.rb
Instance Method Summary collapse
- #cf_routes_output ⇒ Object
-
#initialize(logger, cf_credentials, trace_file) ⇒ CfCommandRunner
constructor
A new instance of CfCommandRunner.
- #login ⇒ Object
- #map_routes(app) ⇒ Object
- #new_app ⇒ Object
- #push(deploy_target_app) ⇒ Object
- #start(deploy_target_app) ⇒ Object
- #takedown_old_target_app(app) ⇒ Object
- #unmap_routes(app) ⇒ Object
Constructor Details
#initialize(logger, cf_credentials, trace_file) ⇒ CfCommandRunner
Returns a new instance of CfCommandRunner.
6 7 8 9 10 |
# File 'lib/bookbinder/cf_command_runner.rb', line 6 def initialize(logger, cf_credentials, trace_file) @logger = logger @creds = cf_credentials @trace_file = trace_file end |
Instance Method Details
#cf_routes_output ⇒ Object
24 25 26 27 28 |
# File 'lib/bookbinder/cf_command_runner.rb', line 24 def cf_routes_output output, status = Open3.capture2("CF_COLOR=false #{cf_binary_path} routes") raise 'failure executing cf routes' unless status.success? output end |
#login ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bookbinder/cf_command_runner.rb', line 12 def login username = creds.username password = creds.password api_endpoint = creds.api_endpoint organization = creds.organization space = creds.space creds_string = (username && password) ? "-u '#{username}' -p '#{password}'" : '' success = Kernel.system("#{cf_binary_path} login #{creds_string} -a '#{api_endpoint}' -o '#{organization}' -s '#{space}'") raise "Could not log in to #{creds.api_endpoint}" unless success end |
#map_routes(app) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bookbinder/cf_command_runner.rb', line 54 def map_routes(app) succeeded = [] creds.flat_routes.each do |domain, name| begin map_route(app, domain, name) succeeded << [app, domain, name] rescue RuntimeError succeeded.each { |app, domain, host| unmap_route(app, domain, host) } raise end end end |
#new_app ⇒ Object
30 31 32 |
# File 'lib/bookbinder/cf_command_runner.rb', line 30 def new_app BlueGreenApp.new([creds.app_name, 'blue'].join('-')) end |
#push(deploy_target_app) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/bookbinder/cf_command_runner.rb', line 41 def push(deploy_target_app) # Currently --no-routes is used to blow away all existing routes from a newly deployed app. # The routes will then be recreated from the creds repo. success = Kernel.system(environment_variables, "#{cf_binary_path} push #{deploy_target_app} --no-route -m 256M -i 3") raise "Could not deploy app to #{deploy_target_app}" unless success end |
#start(deploy_target_app) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bookbinder/cf_command_runner.rb', line 34 def start(deploy_target_app) # Theoretically we shouldn't need this (and corresponding "stop" below), but we've seen CF pull files from both # green and blue when a DNS redirect points to HOST.cfapps.io # Also, shutting down the unused app saves $$ Kernel.system("#{cf_binary_path} start #{deploy_target_app} ") end |
#takedown_old_target_app(app) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bookbinder/cf_command_runner.rb', line 68 def takedown_old_target_app(app) # Routers flush every 10 seconds (but not guaranteed), so wait a bit longer than that. @logger.log "waiting 15 seconds for routes to remap...\n\n" (1..15).to_a.reverse.each do |seconds| @logger.log_print "\r\r#{seconds}... " Kernel.sleep 1 end stop(app) unmap_routes(app) end |
#unmap_routes(app) ⇒ Object
48 49 50 51 52 |
# File 'lib/bookbinder/cf_command_runner.rb', line 48 def unmap_routes(app) creds.flat_routes.each do |domain, host| unmap_route(app, domain, host) end end |