Created
August 13, 2009 18:40
-
-
Save nuex/167372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :application, '{project}' | |
set :repository, 'ssh://code.myhost.net/var/git/{project}.git' | |
set :web_command, 'sudo apache2ctl' | |
desc 'Staging environment' | |
task :staging do | |
set :repository, '/var/git/{project}.git' | |
set :environment, 'staging' | |
set :domain, 'staging1' | |
set :deploy_to, '/var/staging/{project}' | |
end | |
desc 'Production environment' | |
task :production do | |
set :environment, 'production' | |
set :domain, 'rack1' | |
set :deploy_to, '/var/sites/{project}' | |
end | |
desc 'Internal environment' | |
task :internal do | |
set :environment, 'internal' | |
set :domain, 'internal' | |
set :deploy_to, '/var/internal/{project}' | |
end | |
namespace :vlad do | |
remote_task :deploy => [:setup, :setup_db, :symlinks, :setup_apache] | |
remote_task :setup do | |
run <<-CMD | |
mkdir -p #{deploy_to} #{shared_path}/config #{shared_path}/system && \ | |
git clone #{repository} #{current_path} && \ | |
cd #{current_path} && \ | |
git submodule update --init && \ | |
echo "production: | |
adapter: mysql | |
username: root | |
password: | |
database: #{application} | |
development: | |
production" > #{shared_path}/config/database.yml | |
CMD | |
end | |
remote_task :setup_db do | |
run "mysqladmin -uroot create #{application}" | |
run_tasks [:'db:upload', :'db:update'] | |
end | |
remote_task :setup_apache do | |
system %{cat config/deployment/vhost_#{environment} | ssh #{domain} 'sudo sh -c "cat - > /etc/apache2/sites-available/#{application}"'} | |
sudo "a2ensite #{application} && \ | |
apache2ctl graceful" | |
end | |
remote_task :update do | |
run "cd #{current_path}; git fetch origin; git reset --hard #{branch}; git submodule update --init" | |
end | |
remote_task :migrate do | |
run "cd #{current_path}; rake RAILS_ENV=production db:migrate" | |
end | |
remote_task :rollback do | |
run "cd #{current_path}; git reset --soft HEAD^" | |
end | |
remote_task :symlink do | |
set :symlinks, %w( | |
config/database.yml | |
) | |
commands = symlinks.map do |path| | |
"rm -rf #{current_path}/#{path} && \ | |
ln -s #{shared_path}/#{path} #{current_path}/#{path}" | |
end | |
run "mkdir -p #{current_path}/tmp && \ | |
mkdir -p #{current_path}/config" | |
run <<-CMD | |
cd #{current_path} && | |
#{commands.join(" && ")} | |
CMD | |
end | |
namespace :db do | |
set :dump_path, "#{deploy_to}/shared/system/#{application}.sql" | |
remote_task :upload do | |
rsync "config/deployment/#{application}.sql", dump_path | |
end | |
remote_task :update do | |
run "mysql -uroot #{application} < #{dump_path}" | |
end | |
task :dump do | |
system "mysqldump -uroot #{application} config/deployment/#{application}.sql" | |
end | |
remote_task :push => [:dump, :upload, :update] | |
task :pull do | |
system "ssh #{domain} 'mysqldump -uroot #{application}' > config/deployment/#{application}.sql && \ | |
mysql -uroot #{application} < config/deployment/#{application}.sql" | |
end | |
end | |
private | |
def run_tasks tasks | |
tasks.each do |task| | |
t=task.to_sym | |
Rake::Task["vlad:#{t.to_s}"].invoke | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment