Class: Paratrooper::Deploy
- Inherits:
-
Object
- Object
- Paratrooper::Deploy
- Includes:
- Callbacks
- Defined in:
- lib/paratrooper/deploy.rb
Overview
Public: Entry point into the library.
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#deployment_host ⇒ Object
Returns the value of attribute deployment_host.
-
#heroku ⇒ Object
Returns the value of attribute heroku.
-
#match_tag_name ⇒ Object
Returns the value of attribute match_tag_name.
-
#migration_check ⇒ Object
Returns the value of attribute migration_check.
-
#notifiers ⇒ Object
Returns the value of attribute notifiers.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#screen_notifier ⇒ Object
Returns the value of attribute screen_notifier.
-
#system_caller ⇒ Object
Returns the value of attribute system_caller.
-
#tag_name ⇒ Object
Returns the value of attribute tag_name.
Instance Method Summary collapse
-
#activate_maintenance_mode ⇒ Object
Public: Activates Heroku maintenance mode.
-
#add_remote_task(task_name) ⇒ Object
Public: Runs task on your heroku instance.
-
#app_restart ⇒ Object
Public: Restarts application on Heroku.
-
#deactivate_maintenance_mode ⇒ Object
Public: Deactivates Heroku maintenance mode.
-
#default_deploy ⇒ Object
(also: #deploy)
Public: Execute common deploy steps.
-
#initialize(app_name, options = {}, &block) ⇒ Deploy
constructor
Public: Initializes a Deploy.
-
#push_repo ⇒ Object
Public: Pushes repository to Heroku.
-
#run_migrations ⇒ Object
Public: Runs rails database migrations on your application.
-
#setup ⇒ Object
Public: Hook method called first in the deploy process.
-
#teardown ⇒ Object
Public: Hook method called last in the deploy process.
-
#update_repo_tag ⇒ Object
Public: Creates a git tag and pushes it to repository.
-
#warm_instance(wait_time = 3) ⇒ Object
Public: cURL for application URL to start your Heroku dyno.
Methods included from Callbacks
Constructor Details
#initialize(app_name, options = {}, &block) ⇒ Deploy
Public: Initializes a Deploy
app_name - A String naming the Heroku application to be interacted with. options - The Hash options is used to provide additional functionality.
:screen_notifier - Object used for outputting to screen
(optional).
:notifiers - Array of objects interested in being
notified of steps in deployment process
(optional).
:heroku - Object wrapper around heroku-api (optional).
:tag - String name to be used as a git reference
point (optional).
:match_tag - String name of git reference point to match
:tag to (optional).
:system_caller - Object responsible for calling system
commands (optional).
:protocol - String web protocol to be used when pinging
application (optional, default: 'http').
:deployment_host - String host name to be used in git URL
(optional, default: 'heroku.com').
:migration_check - Object responsible for checking pending
migrations (optional).
:api_key - String version of heroku api key.
(default: looks in local Netrc file).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/paratrooper/deploy.rb', line 45 def initialize(app_name, = {}, &block) @app_name = app_name @screen_notifier = [:screen_notifier] || Notifiers::ScreenNotifier.new @notifiers = [:notifiers] || [@screen_notifier] @heroku = [:heroku] || HerokuWrapper.new(app_name, ) @tag_name = [:tag] @match_tag_name = [:match_tag] || 'master' @system_caller = [:system_caller] || SystemCaller.new(debug) @protocol = [:protocol] || 'http' @deployment_host = [:deployment_host] || 'heroku.com' @debug = [:debug] || false @migration_check = [:migration_check] || PendingMigrationCheck.new(match_tag_name, heroku, system_caller) block.call(self) if block_given? end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def app_name @app_name end |
#debug ⇒ Object
Returns the value of attribute debug.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def debug @debug end |
#deployment_host ⇒ Object
Returns the value of attribute deployment_host.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def deployment_host @deployment_host end |
#heroku ⇒ Object
Returns the value of attribute heroku.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def heroku @heroku end |
#match_tag_name ⇒ Object
Returns the value of attribute match_tag_name.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def match_tag_name @match_tag_name end |
#migration_check ⇒ Object
Returns the value of attribute migration_check.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def migration_check @migration_check end |
#notifiers ⇒ Object
Returns the value of attribute notifiers.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def notifiers @notifiers end |
#protocol ⇒ Object
Returns the value of attribute protocol.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def protocol @protocol end |
#screen_notifier ⇒ Object
Returns the value of attribute screen_notifier.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def screen_notifier @screen_notifier end |
#system_caller ⇒ Object
Returns the value of attribute system_caller.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def system_caller @system_caller end |
#tag_name ⇒ Object
Returns the value of attribute tag_name.
14 15 16 |
# File 'lib/paratrooper/deploy.rb', line 14 def tag_name @tag_name end |
Instance Method Details
#activate_maintenance_mode ⇒ Object
Public: Activates Heroku maintenance mode.
80 81 82 83 84 85 86 |
# File 'lib/paratrooper/deploy.rb', line 80 def activate_maintenance_mode return unless pending_migrations? callback(:activate_maintenance_mode) do notify(:activate_maintenance_mode) heroku.app_maintenance_on end end |
#add_remote_task(task_name) ⇒ Object
Public: Runs task on your heroku instance.
task_name - String name of task to run on heroku instance
182 183 184 |
# File 'lib/paratrooper/deploy.rb', line 182 def add_remote_task(task_name) heroku.run_task(task_name) end |
#app_restart ⇒ Object
Public: Restarts application on Heroku.
132 133 134 135 136 137 138 |
# File 'lib/paratrooper/deploy.rb', line 132 def app_restart return unless restart_required? callback(:app_restart) do notify(:app_restart) heroku.app_restart end end |
#deactivate_maintenance_mode ⇒ Object
Public: Deactivates Heroku maintenance mode.
90 91 92 93 94 95 96 |
# File 'lib/paratrooper/deploy.rb', line 90 def deactivate_maintenance_mode return unless pending_migrations? callback(:deactivate_maintenance_mode) do notify(:deactivate_maintenance_mode) heroku.app_maintenance_off end end |
#default_deploy ⇒ Object Also known as: deploy
Public: Execute common deploy steps.
Default deploy consists of:
-
Activating maintenance page
-
Updating repository tag
-
Pushing repository to Heroku
-
Running database migrations
-
Restarting application on Heroku
-
Deactivating maintenance page
-
cURL’ing application URL to warm Heroku dyno
Alias: #deploy
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/paratrooper/deploy.rb', line 165 def default_deploy setup activate_maintenance_mode update_repo_tag push_repo run_migrations app_restart deactivate_maintenance_mode warm_instance teardown end |
#push_repo ⇒ Object
Public: Pushes repository to Heroku.
112 113 114 115 116 117 118 |
# File 'lib/paratrooper/deploy.rb', line 112 def push_repo reference_point = tag_name || 'master' callback(:push_repo) do notify(:push_repo, reference_point: reference_point) system_call "git push -f #{deployment_remote} #{reference_point}:refs/heads/master" end end |
#run_migrations ⇒ Object
Public: Runs rails database migrations on your application.
122 123 124 125 126 127 128 |
# File 'lib/paratrooper/deploy.rb', line 122 def run_migrations return unless pending_migrations? callback(:run_migrations) do notify(:run_migrations) heroku.run_migrations end end |
#setup ⇒ Object
Public: Hook method called first in the deploy process.
63 64 65 66 67 68 |
# File 'lib/paratrooper/deploy.rb', line 63 def setup callback(:setup) do notify(:setup) migration_check.last_deployed_commit end end |
#teardown ⇒ Object
Public: Hook method called last in the deploy process.
72 73 74 75 76 |
# File 'lib/paratrooper/deploy.rb', line 72 def teardown callback(:teardown) do notify(:teardown) end end |
#update_repo_tag ⇒ Object
Public: Creates a git tag and pushes it to repository.
100 101 102 103 104 105 106 107 108 |
# File 'lib/paratrooper/deploy.rb', line 100 def update_repo_tag unless tag_name.nil? || tag_name.empty? callback(:update_repo_tag) do notify(:update_repo_tag) system_call "git tag #{tag_name} #{match_tag_name} -f" system_call "git push -f origin #{tag_name}" end end end |
#warm_instance(wait_time = 3) ⇒ Object
Public: cURL for application URL to start your Heroku dyno.
wait_time - Integer length of time (seconds) to wait before making call
to app
145 146 147 148 149 150 151 |
# File 'lib/paratrooper/deploy.rb', line 145 def warm_instance(wait_time = 3) callback(:warm_instance) do notify(:warm_instance) sleep wait_time system_call "curl -Il #{protocol}://#{app_url}" end end |