Capistrano::Recipes
A simple number of capistrano recipes to deploy rails application using Capistrano v3.
Installation
Add this line to your application's Gemfile:
gem 'j-cap-recipes', require: false, group: :development
And then execute:
$ bundle
Or install it yourself as:
$ gem install j-cap-recipes
Usage
In the Capfile to include all recipes add:
require 'j-cap-recipes'
If you want to load only specified recipe:
require 'j-cap-recipes/setup'
require 'j-cap-recipes/check'
require 'j-cap-recipes/nginx'
require 'j-cap-recipes/monit'
require 'j-cap-recipes/database'
require 'j-cap-recipes/delayed_job'
require 'j-cap-recipes/log'
require 'j-cap-recipes/rails'
require 'j-cap-recipes/unicorn'
require 'j-cap-recipes/honeybadger'
require 'j-cap-recipes/airbrake'
Nginx
Setup
Check
Monit
Rails
To run remote rails console you should update to the latest gems capistrano-rbenv and capistrano-bundler
and run command cap production rails:console.
To setup a custom database.yml config you should provide the directory of the templates
set :template_dir, `config/deploy/templates`
After you should create a file database.yml.erb example:
# store your custom template at foo/bar/database.yml.erb `set :template_dir, "foo/bar"`
#
# example of database template
base: &base
adapter: postgresql
encoding: unicode
timeout: 5000
username: deployer
password: <%#= ask(:db_password, SecureRandom.base64(6)) && fetch(:db_password) %>
host: localhost
port: 5432
test:
database: <%= fetch(:application) %>_test
<<: *base
<%= fetch(:rails_env).to_s %>:
database: <%= fetch(:application) %>_<%= fetch(:rails_env).to_s %>
<<: *base
Honeybadger
honeybadger:deploy - notify the service about deploy and it would be invoked after deploy:migrate
Handy
Support to manage https://github.com/bigbinary/handy config files. First should add require 'j-cap-recipes/handy' to Capfile.
There are three tasks available:
cap staging config:settingsShow the current staging config files;cap staging config:settings:deleteRemove the custom env settings file;cap staging config:settings:uploadUpdate the remote config file with local one;
Git
First should add require 'j-cap-recipes/git' to Capfile.
cap staging git:release:tagCreate tag in local repo by variablegit_tag_nameExample of usage in yourdeploy.rb:
set :git_tag_name, proc { Time.now.to_s.gsub(/[\s\+]+/, '_') }
after 'deploy:finished', 'git:release:tag'
Files
Add 'j-cap-recipes/git'toCapfile.
And now you have task to download any remote file to local via:
bundle exec cap staging "files:download[config/database.yml]".
You will finddownload.tarfile in current directory withconfig/database.yml`.
To download all share folder use:
bundle exec cap staging "files:download[.]"
To extract the archive tar -xvf download.tar -C tmp
Airbrake
Add 'j-cap-recipes/airbrake'toCapfile`. The original version capistrano task to notify airbrake service support only
Capistrano version 2. Migrate the task to support version 3.
To send Airbrake deploy notification, you should also add hook to deploy.rb
after 'deploy:finishing', 'airbrake:deploy'
You can change the default api key using ENV['API_KEY'].
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request

