Skip to content

Instantly share code, notes, and snippets.

@stephenmckinney
Created February 10, 2012 16:37
Show Gist options
  • Save stephenmckinney/1790695 to your computer and use it in GitHub Desktop.
Save stephenmckinney/1790695 to your computer and use it in GitHub Desktop.
Capistrano task to run South migrations and collect static media
after "deploy", "deploy:migrate", "deploy:static", "deploy:restart", "custom:git:tag"
namespace :deploy do
[:stop, :start, :restart, :reload].each do |action|
desc "#{action.to_s.capitalize} Apache."
task action, :roles => :app do
run "sudo /etc/init.d/apache2 #{action.to_s}"
end
end
desc <<-DESC
Run South migrations.
Runs South migrations after performing a database backup.
Usage:
Default:
'deploy:migrate' runs 'python manage.py migrate --all'
One argument:
'deploy:migrate args=pages' runs 'python manage.py migrate gsn'
Multiple arguments:
'deploy:migrate args="gsn pages"' runs 'python manage.py migrate gsn pages'
DESC
task :migrate, :roles => :db, :only => { :primary => true } do
args = ENV['args'] || "--all"
db.backup
run ". /var/apps/nti_env/bin/activate && python #{current_path}/manage.py migrate --noinput #{args}"
end
desc <<-DESC
Collect static files from apps and other locations.
Runs './manage.py collectstatic' on the server after chown'ing several directories
DESC
task :static do
run ". /var/apps/nti_env/bin/activate && python #{current_path}/manage.py collectstatic --noinput"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment