Class: Herkko::Runner
- Inherits:
-
Object
- Object
- Herkko::Runner
- Defined in:
- lib/herkko/runner.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #call ⇒ Object
- #changelog ⇒ Object
- #console ⇒ Object
- #deploy ⇒ Object
- #disable_maintenance_mode ⇒ Object
- #enable_maintenance_mode ⇒ Object
- #forced? ⇒ Boolean
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #migrate ⇒ Object
- #print_usage ⇒ Object
- #print_version ⇒ Object
- #push_new_code ⇒ Object
- #seed ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 12 13 14 |
# File 'lib/herkko/runner.rb', line 8 def initialize(argv) argv.dup.tap do |arguments| @environment = arguments.shift @command = arguments.shift @arguments = arguments unless arguments.empty? end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/herkko/runner.rb', line 6 def arguments @arguments end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/herkko/runner.rb', line 6 def command @command end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
6 7 8 |
# File 'lib/herkko/runner.rb', line 6 def environment @environment end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/herkko/runner.rb', line 16 def call if ["version", "--version"].include?(environment) return print_version end if ["help", "--help", "usage"].include?(environment) return print_usage end return print_usage if environment.nil? || command.nil? if respond_to?(command) public_send(command) else Herkko.run_with_output("heroku", command, arguments, "-r#{environment}") end end |
#changelog ⇒ Object
42 43 44 45 |
# File 'lib/herkko/runner.rb', line 42 def changelog fetch_currently_deployed_version puts git_changelog end |
#console ⇒ Object
86 87 88 |
# File 'lib/herkko/runner.rb', line 86 def console Herkko.run_with_output "heroku run rails console -r #{environment}" end |
#deploy ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/herkko/runner.rb', line 47 def deploy Herkko.info "Doing #{forced? ? "forced(!) " : ""}deployment to #{environment}..." fetch_currently_deployed_version Herkko.info("Deploying changes:") puts puts git_changelog puts ci_state = if skip_ci_check? :skip else check_ci end if ci_state == :green Herkko.info "CI is green. Deploying..." deploy! elsif ci_state == :skip Herkko.info "Skipping CI. Deploying..." deploy! elsif ci_state == :not_used Herkko.info "CI not in use for this project. Deploying..." deploy! elsif ci_state == :yellow Herkko.info "CI is running. Wait a while." elsif ci_state == :queued Herkko.info "Build is queued in CI. Wait a while." elsif ci_state == :red Herkko.info "CI is red. Not deploying." else Herkko.info "CI is in unknown state (#{ci_state}). Can't continue." end end |
#disable_maintenance_mode ⇒ Object
117 118 119 |
# File 'lib/herkko/runner.rb', line 117 def disable_maintenance_mode Herkko.run_with_output "heroku", "maintenance:off", "-r", environment end |
#enable_maintenance_mode ⇒ Object
113 114 115 |
# File 'lib/herkko/runner.rb', line 113 def enable_maintenance_mode Herkko.run_with_output "heroku", "maintenance:on", "-r", environment end |
#forced? ⇒ Boolean
102 103 104 |
# File 'lib/herkko/runner.rb', line 102 def forced? arguments && arguments.include?("--force") end |
#migrate ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/herkko/runner.rb', line 94 def migrate Herkko.info "Migrating database..." Herkko.run_with_output %{ heroku run rake db:migrate -r #{environment} && heroku restart -r #{environment} } end |
#print_usage ⇒ Object
38 39 40 |
# File 'lib/herkko/runner.rb', line 38 def print_usage Herkko.puts File.read(File.join(File.dirname(__FILE__), "..", "..", "usage.txt")) end |
#print_version ⇒ Object
34 35 36 |
# File 'lib/herkko/runner.rb', line 34 def print_version Herkko.puts "Herkko #{Herkko::VERSION}" end |
#push_new_code ⇒ Object
106 107 108 109 110 111 |
# File 'lib/herkko/runner.rb', line 106 def push_new_code Herkko.info "Pushing commit #{to_be_deployed_sha} from branch #{current_branch} to Heroku..." puts Herkko.run_with_output("git", "push", environment, "#{to_be_deployed_sha}:master", forced? ? "--force" : nil) puts end |
#seed ⇒ Object
90 91 92 |
# File 'lib/herkko/runner.rb', line 90 def seed Herkko.run_with_output "heroku run rake db:seed -r #{environment}" end |