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.
-
#branch_name ⇒ Object
Returns the value of attribute branch_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.
-
#http_client ⇒ Object
Returns the value of attribute http_client.
-
#maintenance ⇒ Object
Returns the value of attribute maintenance.
-
#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.
- #maintenance_mode(&block) ⇒ Object
-
#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 for deploying from specific tag
(optional).
:match_tag - String name of git reference point to match
:tag to (optional).
:branch - String name to be used as a git reference
point for deploying from specific branch
(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).
:maintenance - If true, show maintenance page when pending
migrations exists. False by default (optional).
migrations (optional).
:api_key - String version of heroku api key.
(default: looks in local Netrc file).
:http_client - Object responsible for making http calls
(optional).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/paratrooper/deploy.rb', line 57 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] @branch_name = [:branch] @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) @http_client = [:http_client] || HttpClientWrapper.new @maintenance = [:maintenance] || false block.call(self) if block_given? end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def app_name @app_name end |
#branch_name ⇒ Object
Returns the value of attribute branch_name.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def branch_name @branch_name end |
#debug ⇒ Object
Returns the value of attribute debug.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def debug @debug end |
#deployment_host ⇒ Object
Returns the value of attribute deployment_host.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def deployment_host @deployment_host end |
#heroku ⇒ Object
Returns the value of attribute heroku.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def heroku @heroku end |
#http_client ⇒ Object
Returns the value of attribute http_client.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def http_client @http_client end |
#maintenance ⇒ Object
Returns the value of attribute maintenance.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def maintenance @maintenance end |
#match_tag_name ⇒ Object
Returns the value of attribute match_tag_name.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def match_tag_name @match_tag_name end |
#migration_check ⇒ Object
Returns the value of attribute migration_check.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def migration_check @migration_check end |
#notifiers ⇒ Object
Returns the value of attribute notifiers.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def notifiers @notifiers end |
#protocol ⇒ Object
Returns the value of attribute protocol.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def protocol @protocol end |
#screen_notifier ⇒ Object
Returns the value of attribute screen_notifier.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def screen_notifier @screen_notifier end |
#system_caller ⇒ Object
Returns the value of attribute system_caller.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def system_caller @system_caller end |
#tag_name ⇒ Object
Returns the value of attribute tag_name.
15 16 17 |
# File 'lib/paratrooper/deploy.rb', line 15 def tag_name @tag_name end |
Instance Method Details
#activate_maintenance_mode ⇒ Object
Public: Activates Heroku maintenance mode.
95 96 97 98 99 100 101 |
# File 'lib/paratrooper/deploy.rb', line 95 def activate_maintenance_mode return unless maintenance && 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
206 207 208 |
# File 'lib/paratrooper/deploy.rb', line 206 def add_remote_task(task_name) heroku.run_task(task_name) end |
#app_restart ⇒ Object
Public: Restarts application on Heroku.
156 157 158 159 160 161 162 |
# File 'lib/paratrooper/deploy.rb', line 156 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.
105 106 107 108 109 110 111 |
# File 'lib/paratrooper/deploy.rb', line 105 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
-
Accessing application URL to warm Heroku dyno
Alias: #deploy
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/paratrooper/deploy.rb', line 189 def default_deploy setup update_repo_tag push_repo maintenance_mode do run_migrations app_restart end warm_instance teardown end |
#maintenance_mode(&block) ⇒ Object
113 114 115 116 117 |
# File 'lib/paratrooper/deploy.rb', line 113 def maintenance_mode(&block) activate_maintenance_mode block.call if block_given? deactivate_maintenance_mode end |
#push_repo ⇒ Object
Public: Pushes repository to Heroku.
Based on the following precedence: branch_name / tag_name / ‘master’
136 137 138 139 140 141 142 |
# File 'lib/paratrooper/deploy.rb', line 136 def push_repo reference_point = git_branch_name || git_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.
146 147 148 149 150 151 152 |
# File 'lib/paratrooper/deploy.rb', line 146 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.
78 79 80 81 82 83 |
# File 'lib/paratrooper/deploy.rb', line 78 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.
87 88 89 90 91 |
# File 'lib/paratrooper/deploy.rb', line 87 def teardown callback(:teardown) do notify(:teardown) end end |
#update_repo_tag ⇒ Object
Public: Creates a git tag and pushes it to repository.
121 122 123 124 125 126 127 128 129 |
# File 'lib/paratrooper/deploy.rb', line 121 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
169 170 171 172 173 174 175 |
# File 'lib/paratrooper/deploy.rb', line 169 def warm_instance(wait_time = 3) callback(:warm_instance) do notify(:warm_instance) sleep wait_time http_client.get("#{protocol}://#{app_url}") end end |