Skip to content

Instantly share code, notes, and snippets.

@sandro
Created May 16, 2011 22:55
Show Gist options
  • Save sandro/975556 to your computer and use it in GitHub Desktop.
Save sandro/975556 to your computer and use it in GitHub Desktop.
WIP Whiskey Disk deployment with db backup and lesscss generation
require 'whiskey_disk/rake'
require 'whiskey_disk/helpers'
namespace :deploy do
ENV['to'] ||= 'staging'
def verbose_cmd(cmd)
system %(set -x && #{cmd})
end
desc "backup postgresql db"
task :backup_db => :environment do
c = ActiveRecord::Base.configurations[Rails.env]
verbose_cmd %(
pg\_dump -Fc --no-acl --no-owner #{c['database']} > #{WhiskeyDisk[:db_dumps]}/`date "+%Y-%m-%d_%H-%M-%S"`.sql
)
end
task :post_setup do
verbose_cmd %(
mkdir -p #{WhiskeyDisk[:db_dumps]}
)
puts "Next add database.yml to #{WhiskeyDisk[:deploy_to]}/config"
puts "Then run rake db:setup"
end
desc "run rake db:reset"
task :db_reset do
Rake::Task['db:reset'].invoke unless WhiskeyDisk[:environment] == "production"
end
task :common_post_deploy do
Rake::Task['db:migrate'].invoke if changed?('db/migrate')
verbose_cmd "touch tmp/restart.txt"
end
namespace :staging do
task :post_deploy do
Rake::Task['deploy:common_post_deploy'].invoke
end
end
namespace :production do
task :post_deploy do
Rake::Task['deploy:backup_db'].invoke
Rake::Task['deploy:common_post_deploy'].invoke
end
end
end
which bundle || gem install bundler
bundle check || bundle install --deployment --without=development test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment