# MyProject deployment script # Find out how to use by running "cap -T" in this directory # Use Capistrano's built in deployment management scripts load 'deploy' set :application, "myproject" set :repository, "svn+ssh://dev.example.com/svn/#{application}/trunk" set :deploy_to, "/var/www/#{application}" # I want to export the code from svn locally, bundle it up, and send it to # the server as a tarball set :scm, :subversion set :deploy_via, :copy set :copy_strategy, :export # Right now we're only using one server for everything role :app, "dev.example.com" role :web, "dev.example.com" role :db, "dev.example.com", :primary => true # These additional commands run after the deploy has finished to compress # our javascript files, pre-compile the Python code, and copy back in the # server's local_settings.py file. after :deploy, :js_minify after :deploy, :python_compile after :deploy, :copy_local_settings task :js_minify do run <<-CMD for f in `find #{latest_release}/static/js -name \"*.js\"`; do python #{latest_release}/#{application}/lib/jsmin.py <$f> $f.tmp && mv $f.tmp $f; done; true; CMD end task :python_compile do run "python #{latest_release}/#{application}/scripts/compile.py #{latest_release}/#{application}" end task :copy_local_settings do run "ln -s /usr/lib/python2.5/site-packages/django/contrib/admin/media #{latest_release}/admin_media" run "cp #{deploy_to}/settings_local.py #{latest_release}/#{application}/" end # By default Capistrano will create several directories Rails expects, such as # public, tmp, and log. We don't need them, so we override this function but # maintain the commands to touch individual assets to update their timestamps. deploy.task :finalize_update do run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S") asset_paths = %w(img js css).map { |p| "#{latest_release}/static/#{p}" }.join(" ") run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" } end # The default "restart" task invokes a local "reaper" script. All we need is # an Apache restar to clear out the mod_python shared code stuck in memory. deploy.task :restart, :roles => :app, :except => { :no_release => true } do invoke_command "apache2ctl restart", :via => run_method end