Skip to content

Commit

Permalink
Documentation, making lack of support for capistrano 3 explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
kdonovan committed Dec 21, 2013
1 parent 4a704a3 commit 31910e6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,6 @@
# changelog

## 0.0.4 -- December 20, 2013
* Updated dependecy - does not work with capistrano 3+
* Updated README examples
* Added changelog
46 changes: 36 additions & 10 deletions README.md
Expand Up @@ -2,6 +2,8 @@

This gem extends capistrano deployments to allow certain tasks to only be run under certain conditions -- i.e. conditionally.

It hasn't yet been extended to work with Capistrano 3; pull requests welcomed!

## Installation

Add to your Gemfile:
Expand Down Expand Up @@ -47,27 +49,52 @@ If you need more custom control, <code>:if</code> and <code>:unless</code> expec

## Example Usage

These snippets go in <code>config/deploy.rb</code> or any other file that gets loaded via capistrano.

### A random collection of examples:

#### Using [whenever](https://github.com/javan/whenever)

Only run the rake task to update the crontab if the schedule has changed:

ConditionalDeploy.register :whenever, :watchlist => 'config/schedule.rb' do
after "deploy:symlink", "deploy:update_crontab"
end

ConditionalDeploy.register :sphinx, :watchlist => ['db/schema.rb', 'db/migrate'] do
#### Using [thinking-sphinx](https://github.com/pat/thinking-sphinx)

Only restart the sphinx daemon if our database or schema has changed. Otherwise, just copy the generated sphinx config from the previous release:

SPHINX_WATCHLIST = ['db/schema.rb', 'db/migrate', 'sphinx.yml', 'app/indices']

ConditionalDeploy.register :sphinx, :watchlist => SPHINX_WATCHLIST do
before "deploy:update_code", "thinking_sphinx:stop"
before "deploy:start", "thinking_sphinx:start"
before "deploy:restart", "thinking_sphinx:start"
end

ConditionalDeploy.register :no_sphinx, :none_match => SPHINX_WATCHLIST do
after "deploy:update_code", "sphinx:copy_config"
end

namespace :sphinx do
desc 'Copy the config file from previous release, if available, or else rerun configuration'
task :copy_config, :roles => :app do
run "([ -f #{current_path}/config/#{stage}.sphinx.conf ] && cp #{current_path}/config/#{stage}.sphinx.conf #{release_path}/config/#{stage}.sphinx.conf) || true"
run "[ -f #{release_path}/config/#{stage}.sphinx.conf ] || (cd #{release_path} && bundle exec rake ts:config RAILS_ENV=#{stage})"
end
end


#### Using [jammit](https://github.com/documentcloud/jammit)

For pre-asset-pipeline versions of Rails, this snippet will reprocess your assets with [jammit](https://github.com/documentcloud/jammit) only if necessary:

ConditionalDeploy.register :jammit, :watchlist => ['public/images/embed', 'public/stylesheets', 'public/javascripts', 'public/assets', 'config/assets.yml'] do
after 'deploy:symlink', 'deploy:rebuild_assets'
end

# Restart the resque workers unless the only changes were to static assets, views, or controllers.
ConditionalDeploy.register(:resque, :unless => lambda { |changed| changed.all?{|f| f['public/'] || f['app/controllers/'] || f['app/views/'] } }) do
before "deploy:restart", "resque:workers:restart"
end

# ... note that you still have to actually DEFINE the tasks laid out above (e.g. deploy:update_crontab)

#### Migrations

I've got <code>cap deploy</code> in muscle memory, and I used to find myself forgetting to run <code>cap deploy:migrations</code> until after I tested the new changes and found staging wasn't working right. I now add the following code to my apps, so I never have to worry about it again:

Expand Down Expand Up @@ -95,5 +122,4 @@ If you need to force a particular conditional to run, you can also do that via t

## License

Copyright &copy; 2011 [Deviantech, Inc.](http://www.deviantech.com) and released under the MIT license.

Copyright &copy; 2013 [Deviantech, Inc.](http://www.deviantech.com) and released under the MIT license.
4 changes: 2 additions & 2 deletions capistrano-conditional.gemspec
Expand Up @@ -7,7 +7,7 @@ Gem::Specification.new do |s|
s.version = Capistrano::Conditional::VERSION
s.authors = ["Kali Donovan"]
s.email = ["kali@deviantech.com"]
s.homepage = ""
s.homepage = "https://github.com/deviantech/capistrano-conditional"
s.summary = %q{Adds support for conditional deployment tasks in capistrano}
s.description = %q{Allows making tasks for git-based projects conditional based on the specific files to be deployed.}

Expand All @@ -21,5 +21,5 @@ Gem::Specification.new do |s|
# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
s.add_runtime_dependency "git"
s.add_runtime_dependency "capistrano"
s.add_runtime_dependency "capistrano", '~> 2.5'
end
2 changes: 1 addition & 1 deletion lib/capistrano-conditional/version.rb
@@ -1,5 +1,5 @@
module Capistrano
module Conditional
VERSION = "0.0.3"
VERSION = "0.0.4"
end
end

0 comments on commit 31910e6

Please sign in to comment.