Capistranovelys - Keeping our recipes DRY
This gem, once stable, should include every recipe/task that serves for more than one of our project.
Installation
capistranovelys has a dependency on recent versions of capistrano,
meaning you can remove capistrano and capistrano-ext from your Gemfile, and replace it with :
gem "capistranovelys", :git => '[email protected]:novelys/capistranovelys.git'
Usage
In your deploy.rb :
- remove `require "production_chain/capistrano";
- add
require 'capistrano/novelys'(loads the core recipes) - load recipes you need, eg:
use_stack :database, :rails2, :rbenv, :whenever. To be used BEFORE other loading of recipes such asdeploy/assets, otherwise some hooks (such as the symlinks) will be executed too late.- You can use
use_default_stack_and [arg, ...]. It will loadairbrake,rbenv,unicorn,logs,stages,remote_commands, production_chain, and the recipes supplied as arguments. Useuse_default_stackif you don't want/need anything else.
- You can use
- Make sure you don't have duplicates!
Recipes available
Core
Common setup and options is done here. I suggest reading the file to go through all the details.
Basically, using core means you're using git, you're using rails, and you'll keep 5 releases.
SSH
This gem has a dependency on sushi. This allows you to do capistrano [stage] ssh.
Rails (rails)
Rails 3 & 4 commands.
rails:console: open a rails consolerails:secret_token:copy: copy the secret_token from your local file to the shared pathrails:secret_token:symlink: symlink the secret_token.rb file from the shared path to the current path. Hooked afterdeploy:update_code
Rails 2 (rails2)
Rails 2 commands.
rails2:console: open a rails consolerails2:secret_token:copy: copy the session_store from your local file to the shared pathrails2:secret_token:symlink: symlink the session_store.rb file from the shared path to the current path. Hooked afterdeploy:update_code
Stages (stages)
Replacement with better defaults for stages:
- bundles two stages,
stagingandproduction,stagingbeing the default`; - those stages comes with default for
branchandrails_env; staging can overridebranchat runtime (viacap -S branch=value); - if no stages are specified, stages are defined and loaded by looking in
config/deploy/*.rb
You should not require capistrano/ext/multistage.
Database (database)
database:create: create the databasedatabase:seed: seed the databasedatabase:copy: copy the database.yml from your local file to the shared pathdatabase:symlink: symlink the database.yml file from the shared path to the current path. Hooked afterdeploy:update_code
Mongoid (mongoid)
mongoid:copy: copy the mongoid.yml from your local file to the shared pathmongoid:symlink: symlink the mongoid.yml file from the shared path to the current path. Hooked afterdeploy:update_codemongoid:index: create the indexes
Logs (logs)
logs:tail: tail the logs of the rails app
Production chain (production_chain)
Recipes usings rake tasks from novelys/production_chain
db:dump_and_restore: restore the database from the server to your local env. SupplyFILE=mongoidwhen using mongoid.assets:dump_and_restore: restore the assets from the public direction to your local env.
Rbenv (rbenv)
Setup the default_environment with the correct path for rbenv
Remote commands (remote_commands)
remote:rake: Execute a rake task on the target (eg:cap remote:rake "assets:precompile")remote:command: Execute a shell command on the target (eg:cap remote:command ls)
S3 (s3)
s3:copy: copy the amazon_s3.yml from your local file to the shared paths3:symlink: symlink the amazon_s3.yml file from the shared path to the current path. Hooked afterdeploy:update_code
Unicorn (unicorn)
deploy:start, deploy:stop, deploy:graceful_stop, deploy:reload, deploy:restart tasks for unicorn
Puma (puma)
deploy:start, deploy:stop, deploy:graceful_stop, deploy:reload, deploy:restart tasks for puma. Doesn't actually do anything except requiring "puma".
Airbrake (airbrake)
airbrake:copy: copy the airbrake.rb from your local file to the shared pathairbrake:symlink: symlink the airbrake.rb file from the shared path to the current path. Hooked afterdeploy:update_code
Sphinx (sphinx)
thinking_sphinx:copy: copy the *.sphinx.conf from your local file to the shared paththinking_sphinx:symlink: symlink the *.sphinx.conf file from the shared path to the current path. Hooked afterdeploy:update_code- Every task available under the namespace
thinking_sphinxis also available under the namespacets, eg.ts:rebuild
Sunspot (sunspot)
sunspot:copy: copy the sunspot.yml from your local file to the shared pathsunspot:symlink: symlink the sunspot.yml file from the shared path to the current path. Hooked afterdeploy:update_code
Whenever (whenever)
Setup options for the whenever gem