lib/django-recipes/recipes/deploy.rb in django-recipes-1.0.0 vs lib/django-recipes/recipes/deploy.rb in django-recipes-1.1.0
- old
+ new
@@ -1,92 +1,85 @@
Capistrano::Configuration.instance(:must_exist).load do
namespace :deploy do
- desc "Prepares system for deployment"
- task :setup, :roles => :app do
- run "mkdir -p #{deploy_to}/system"
- run "cd #{deploy_to}; git clone #{repository}"
- create_upload_directories
- make_system_writable
- symlink
- vhost
- end
-
+ desc <<-DESC
+ [internal] Touches up the released code. This is called by update_code \
+ after the basic deploy finishes. It assumes a Rails project was deployed, \
+ so if you are deploying something else, you may want to override this \
+ task with your own environment's requirements.
+
+ This task will make the release group-writable (if the :group_writable \
+ variable is set to true, which is the default). It will then set up \
+ symlinks to the shared directory for the log, system, and tmp/pids \
+ directories, and will lastly touch all assets in {media_root}/images, \
+ {media_root}/stylesheets, and {media_root}/javascripts so that the times are \
+ consistent (so that asset timestamping works). This touch process \
+ is only carried out if the :normalize_asset_timestamps variable is \
+ set to true, which is the default.
+ DESC
+ task :finalize_update, :except => { :no_release => true } do
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
+
+ run <<-CMD
+ ln -s #{shared_path}/system #{latest_release}/#{media_root} &&
+ ln -s #{django_path}/django/contrib/admin/media #{latest_release}/#{media_root}/#{admin_media_root}
+ CMD
+
+ if fetch(:normalize_asset_timestamps, true)
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
+ asset_paths = %w(images stylesheets javascripts).map { |p| "#{latest_release}/#{media_root}/#{p}" }.join(" ")
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
+ end
+ end
+
+ desc <<-DESC
+ [internal] Creates upload directories in /shared/system that your app may need.
+ DESC
task :create_upload_directories, :roles => :app do
upload_directories.each do |dir|
- run "mkdir -p #{system_path}/#{dir}"
+ run "mkdir -p #{shared_path}/system/#{dir}"
end
- make_system_writable
+ writable_directories
end
-
- desc "Deploys to an unitialized server"
- task :cold, :roles => :app do
- setup
- syncdb
- django #runs the deploy:django task
+ after('deploy:setup','deploy:create_upload_directories')
+
+ desc "[internal] Chgrp -R of /shared/system writable by the apache group"
+ task :writable_directories, :roles => :app do
+ sudo "chown -R #{user}:#{apache_group} #{shared_path}/system"
end
-
- desc "Deploy your django app"
- task :django, :roles => :app do
- disable
- run "cd #{deploy_to}/#{application}; git pull"
- reload
- enable
+
+ desc "Starts the application server"
+ task :start, :roles => :app do
+ sudo "#{start_cmd}"
end
-
- task :make_system_writable, :roles => :app do
- run "chgrp -R #{apache_user} #{system_path}"
- run "chmod -R g+wx #{system_path}"
+
+ desc "Stops the application server"
+ task :stop, :roles => :app do
+ sudo "#{stop_cmd}"
end
-
- task :symlink, :roles => :app do
- media_root_symlink
- admin_symlink
- system_symlink
+
+ desc "Restarts the application server"
+ task :restart, :roles => :app do
+ sudo "#{restart_cmd}"
end
-
- task :media_root_symlink, :roles => :app do
- run "ln -sf #{app_path}/#{media_root} #{media_root_path}"
- end
-
- task :system_symlink, :roles => :app do
- run "ln -sf #{system_path} #{media_root_path}/system"
- end
-
- task :admin_symlink, :roles => :app do
- sudo "ln -sf #{django_path}/django/contrib/admin/media #{media_root_path}/#{admin_media_root}"
- end
-
- desc "Creates a vhost for your application and uploads to server"
- task :vhost, :roles => :app do
- put render('django_vhost.vhost',binding), "/tmp/#{vhost_name}"
- sudo "mv /tmp/#{vhost_name} #{vhost_path}/#{vhost_name}"
- end
-
- desc "Run django syncdb"
- task :syncdb, :roles => :app do
- run "cd #{app_path} ; ./manage.py syncdb --setting=#{settings}"
- end
-
- desc "Destroys this app on the server"
- task :destroy, :roles => :app do
- run "rm -rf #{deploy_to}/*"
- sudo "rm #{vhost_path}/#{vhost_name}"
- reload
- end
- desc "Reloads apache"
- task :reload, :roles => :app do
+ desc "Reloads the application server"
+ task :reload, :roles => :app do
sudo "#{reload_cmd}"
end
-
- desc "Enables the website"
- task :enable, :roles => :app do
- run "rm #{system_path}/maintenance.html"
+
+ desc "Deletes everything in #{deploy_to}"
+ task :clobber, :roles => :app do
+ sudo "rm -rf #{deploy_to}/*"
end
+
+ # tasks that don't do anythign with django
+ no_ops = ['migrate', 'migration']
+ no_ops.each do |name|
+ task name do ; end
+ end
- desc "Disable the website"
- task :disable, :roles => :app do
- put render('maintenance.html',binding), "/tmp/maintenance.html"
- run "mv /tmp/maintenance.html #{system_path}/maintenance.html"
+ desc "Runs syncdb"
+ task :syncdb, :roles => :app do
+ run "cd #{app_path} ; ./manage.py syncdb --setting=#{settings}"
end
end
end
\ No newline at end of file