Skip to content

Instantly share code, notes, and snippets.

@sandro
Created August 5, 2010 03:28
Show Gist options
  • Save sandro/509178 to your computer and use it in GitHub Desktop.
Save sandro/509178 to your computer and use it in GitHub Desktop.
# Dicking around with various setups
# We can define the custom hooks in the deploy rake task itself because
# rake is still the main interface for deployments - no need for a
# separate whiskey_disk_hooks.rb file
require 'whiskey_disk/rake'
# I don't love the way this turned out but the ideas is that WhiskeyDisk
# provides a command-api to build local and remote commands.
class GemCache < WhiskeyDisk::Command
def local_commands
enqueue_local("bundle package")
enqueue_local("rsync -vahcz vendor/cache -e ssh #{self[:domain]}:#{self[:deploy_to]}/vendor/")
enqueue_local("rm -rf vendor/cache")
end
def remote_commands
in_project do
enqueue_remote('bundle check || bundle install --local --without=development test')
end
end
# superclass
def in_project
enqueue_remote "cd #{self[:deploy_to]}"
yield
enqueue_remote "cd -"
end
# superclass
def run
system local_buffer.join(" && ")
remote_system remote_buffer.join(" && ")
end
end
# After you have a bunch of commands, add them to the appropriate callback handler:
# WhiskeyDisk.after_setup = [BuildSharedDirectory, BundleInstall]
# WhiskeyDisk.after_deploy = [BundleInstall, Migrate, ReindexThinkingSphinx]
# WhiskeyDisk.before_exit = [RestartPassenger]
# These classes could be overkill though.
# Instance eval the hooks.
WhiskeyDisk.post_setup_buffer do
enqueue "bundle install"
enqueue "mkdir -p #{self[:shared]}/config"
end
WhiskeyDisk.post_deploy_buffer do
enqueue "bundle install"
enqueue "ln -sf #{self[:shared]}/config/database.yml #{self[:deploy_to]}/config/database.yml"
end
WhiskeyDisk.before_close_buffer do
enqueue "touch tmp/restart.txt"
end
# The rake tasks can still be used.
namespace :deploy do
task :gem_cache do
GemCache.run
end
task :post_deploy => :environment do
PageCache.expire!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment