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
45 46 47 48 |
# File 'lib/herkko/runner.rb', line 45 def changelog fetch_currently_deployed_version puts git_changelog end |
#console ⇒ Object
92 93 94 |
# File 'lib/herkko/runner.rb', line 92 def console Herkko.run_with_output "heroku run rails console -r #{environment}" end |
#deploy ⇒ Object
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 85 86 87 88 89 90 |
# File 'lib/herkko/runner.rb', line 50 def deploy Herkko.info "Doing #{forced? ? "forced(!) " : ""}deployment to #{environment}..." fetch_currently_deployed_version Herkko.info "Pushing commit #{to_be_deployed_sha} from branch #{current_branch} to Heroku..." puts 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
127 128 129 |
# File 'lib/herkko/runner.rb', line 127 def disable_maintenance_mode Herkko.run_with_output "heroku", "maintenance:off", "-r", environment end |
#enable_maintenance_mode ⇒ Object
123 124 125 |
# File 'lib/herkko/runner.rb', line 123 def enable_maintenance_mode Herkko.run_with_output "heroku", "maintenance:on", "-r", environment end |
#forced? ⇒ Boolean
108 109 110 |
# File 'lib/herkko/runner.rb', line 108 def forced? arguments && arguments.include?("--force") end |
#migrate ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/herkko/runner.rb', line 100 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 41 42 43 |
# File 'lib/herkko/runner.rb', line 38 def print_usage usage_contents = File.read( File.join(File.dirname(__FILE__), "..", "..", "usage.txt") ) Herkko.puts usage_contents 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
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/herkko/runner.rb', line 112 def push_new_code Herkko.run_with_output( "git", "push", environment, "#{to_be_deployed_sha}:master", forced? ? "--force" : nil ) puts end |
#seed ⇒ Object
96 97 98 |
# File 'lib/herkko/runner.rb', line 96 def seed Herkko.run_with_output "heroku run rake db:seed -r #{environment}" end |