2013-07-15 00:21:10 +08:00
|
|
|
---
|
|
|
|
title: Flow
|
|
|
|
layout: default
|
|
|
|
---
|
|
|
|
|
|
|
|
Capistrano v3 provides a default **deploy flow** and a **rollback flow**:
|
|
|
|
|
|
|
|
### Deploy flow
|
|
|
|
|
|
|
|
When you run `cap production deploy`, it invokes the following tasks in
|
|
|
|
sequence:
|
|
|
|
|
2014-01-03 22:41:22 +01:00
|
|
|
{% highlight ruby %}
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy:starting - start a deployment, make sure everything is ready
|
|
|
|
deploy:started - started hook (for custom tasks)
|
|
|
|
deploy:updating - update server(s) with a new release
|
|
|
|
deploy:updated - updated hook
|
|
|
|
deploy:publishing - publish the new release
|
|
|
|
deploy:published - published hook
|
|
|
|
deploy:finishing - finish the deployment, clean up everything
|
|
|
|
deploy:finished - finished hook
|
2014-01-03 22:41:22 +01:00
|
|
|
{% endhighlight %}
|
2013-07-15 00:21:10 +08:00
|
|
|
|
|
|
|
Notice there are several hook tasks e.g. `:started`, `:updated` for
|
|
|
|
you to hook up custom tasks into the flow using `after()` and `before()`.
|
|
|
|
|
|
|
|
### Rollback flow
|
|
|
|
|
|
|
|
When you run `cap production deploy:rollback`, it invokes the following
|
|
|
|
tasks in sequence:
|
|
|
|
|
2014-01-03 22:41:22 +01:00
|
|
|
{% highlight ruby %}
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy:starting
|
|
|
|
deploy:started
|
|
|
|
deploy:reverting - revert server(s) to previous release
|
|
|
|
deploy:reverted - reverted hook
|
|
|
|
deploy:publishing
|
|
|
|
deploy:published
|
|
|
|
deploy:finishing_rollback - finish the rollback, clean up everything
|
|
|
|
deploy:finished
|
2014-01-03 22:41:22 +01:00
|
|
|
{% endhighlight %}
|
2013-07-15 00:21:10 +08:00
|
|
|
|
|
|
|
As you can see, rollback flow shares many tasks with deploy flow. But note that, rollback flow runs its own `:finishing_rollback` task because its
|
|
|
|
cleanup process is usually different from deploy flow.
|
|
|
|
|
|
|
|
### Flow examples
|
|
|
|
|
|
|
|
Assume you require the following files in `Capfile`,
|
|
|
|
|
2014-01-03 22:41:22 +01:00
|
|
|
{% highlight ruby %}
|
2013-07-15 00:21:10 +08:00
|
|
|
# Capfile
|
|
|
|
require 'capistrano/setup'
|
|
|
|
require 'capistrano/deploy'
|
|
|
|
require 'capistrano/bundler'
|
|
|
|
require 'capistrano/rails/migrations'
|
|
|
|
require 'capistrano/rails/assets'
|
2014-01-03 22:41:22 +01:00
|
|
|
{% endhighlight %}
|
2013-07-15 00:21:10 +08:00
|
|
|
|
2013-07-15 23:49:11 +08:00
|
|
|
When you run `cap production deploy`, it runs these tasks:
|
2013-07-15 00:21:10 +08:00
|
|
|
|
2014-01-03 22:41:22 +01:00
|
|
|
{% highlight ruby %}
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy
|
|
|
|
deploy:starting
|
|
|
|
[before]
|
|
|
|
deploy:ensure_stage
|
2013-07-15 23:40:43 +08:00
|
|
|
deploy:set_shared_assets
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy:check
|
|
|
|
deploy:started
|
|
|
|
deploy:updating
|
|
|
|
git:create_release
|
|
|
|
deploy:symlink:shared
|
|
|
|
deploy:updated
|
|
|
|
[before]
|
|
|
|
deploy:bundle
|
|
|
|
[after]
|
|
|
|
deploy:migrate
|
|
|
|
deploy:compile_assets
|
|
|
|
deploy:normalise_assets
|
|
|
|
deploy:publishing
|
|
|
|
deploy:symlink:release
|
|
|
|
deploy:restart
|
|
|
|
deploy:published
|
|
|
|
deploy:finishing
|
|
|
|
deploy:cleanup
|
|
|
|
deploy:finished
|
|
|
|
deploy:log_revision
|
2014-01-03 22:41:22 +01:00
|
|
|
{% endhighlight %}
|
2013-07-15 00:21:10 +08:00
|
|
|
|
|
|
|
For `cap production deploy:rollback`, it runs these tasks:
|
|
|
|
|
2014-01-03 22:41:22 +01:00
|
|
|
{% highlight ruby %}
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy
|
|
|
|
deploy:starting
|
|
|
|
[before]
|
|
|
|
deploy:ensure_stage
|
2013-07-15 23:28:17 +08:00
|
|
|
deploy:set_shared_assets
|
2013-07-15 00:21:10 +08:00
|
|
|
deploy:check
|
|
|
|
deploy:started
|
|
|
|
deploy:reverting
|
|
|
|
deploy:revert_release
|
|
|
|
deploy:reverted
|
|
|
|
[after]
|
|
|
|
deploy:rollback_assets
|
|
|
|
deploy:publishing
|
|
|
|
deploy:symlink:release
|
|
|
|
deploy:restart
|
|
|
|
deploy:published
|
|
|
|
deploy:finishing_rollback
|
|
|
|
deploy:cleanup_rollback
|
|
|
|
deploy:finished
|
|
|
|
deploy:log_revision
|
2014-01-03 22:41:22 +01:00
|
|
|
{% endhighlight %}
|
2013-07-15 16:17:52 +08:00
|
|
|
|