mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Initial attempt at a cookbook
This commit is contained in:
parent
30e3461824
commit
7d33d6d3ec
2 changed files with 55 additions and 0 deletions
|
@ -31,6 +31,7 @@
|
||||||
<li><a href="/documentation/getting-started/local-tasks/">Local Tasks</a></li>
|
<li><a href="/documentation/getting-started/local-tasks/">Local Tasks</a></li>
|
||||||
<li><a href="/documentation/getting-started/before-after/">Before / After Hooks</a></li>
|
<li><a href="/documentation/getting-started/before-after/">Before / After Hooks</a></li>
|
||||||
<li><a href="/documentation/getting-started/authentication-and-authorisation/">Authentication & Authorisation</a></li>
|
<li><a href="/documentation/getting-started/authentication-and-authorisation/">Authentication & Authorisation</a></li>
|
||||||
|
<li><a href="/documentation/getting-started/cookbook/">Task Cookbook</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
|
|
||||||
<h5>Advanced Features</h5>
|
<h5>Advanced Features</h5>
|
||||||
|
|
54
docs/documentation/getting-started/cookbook/index.markdown
Normal file
54
docs/documentation/getting-started/cookbook/index.markdown
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
---
|
||||||
|
title: Task Cookbook
|
||||||
|
layout: default
|
||||||
|
---
|
||||||
|
|
||||||
|
This page documents common custom tasks for specific use cases. It is hoped that these will be copied and modified for your use case, and also provide a basis for understanding how to extend Capistrano for your own usage.
|
||||||
|
|
||||||
|
You can also look in most Capistrano repositories (including core) for rake tasks to see further example of how it works.
|
||||||
|
|
||||||
|
Feel free to contribute more via a Pull Request.
|
||||||
|
|
||||||
|
## Rails
|
||||||
|
|
||||||
|
Many of these tasks probably require [Capistrano::Rails](https://github.com/capistrano/rails).
|
||||||
|
|
||||||
|
### Run arbitrary rake tasks from environment variables
|
||||||
|
|
||||||
|
From [Capistrano/Rails PR #209](https://github.com/capistrano/rails/pull/209)
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
namespace :ruby do
|
||||||
|
desc 'Runs any rake task, cap deploy:rake task=db:rollback'
|
||||||
|
task rake: [:set_rails_env] do
|
||||||
|
on release_roles([:db]) do
|
||||||
|
within release_path do
|
||||||
|
with rails_env: fetch(:rails_env) do
|
||||||
|
execute :rake, ENV['task']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Passes in the rake task to be run via an environment variable. Also a simple example of running a rake task on the server.
|
||||||
|
|
||||||
|
|
||||||
|
### Conditional migrations
|
||||||
|
|
||||||
|
Arising from [Capistrano/Rails issue #199](https://github.com/capistrano/rails/issues/199)
|
||||||
|
|
||||||
|
A frequent issue on deploy are slow migrations which involve downtime. In this case, you often want to run the migrations conditionally, where the main deploy doesn't run them, but you can do so manually at a better point. To do so, you could put the following in your `Capfile`:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
if ENV['RUN_MIGRATIONS'].present?
|
||||||
|
require 'capistrano/rails/migrations'
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Now the migrations do not run by default, but they will run with the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
RUN_MIGRATIONS=true bundle exec cap production deploy:migrate
|
||||||
|
```
|
Loading…
Reference in a new issue