namespace(:deploy) do desc "Symlink shared files and directories." task(:symlink_files) do [:shared_dirs, :shared_files].map { |var| fetch(var, []) }.flatten.each do |path| source = "#{latest_release}/#{path}" destination = "#{shared_path}/#{path}" d = destination dp = File.dirname(destination) p = previous_release r = path s = source run <<-CMD [ -e #{d} ] || { mkdir -p #{dp} && { if [[ "#{p}" ]] && [ -e #{p}/#{r} ]; then cp -r #{p}/#{r} #{d}; elif [ -e #{s} ]; then cp -r #{s} #{d}; fi } }; rm -rf #{source} && ln -nfs #{destination} #{source} CMD end end after('deploy:finalize_update') { symlink_files } task :delete_mac_os_metadata_files do run "cd #{latest_release} && find . | egrep '(^|/)\\._' | xargs rm 2>/dev/null; true" end after('deploy:finalize_update') { delete_mac_os_metadata_files } desc "Download files from the current revision." task :download do (ENV["FILES"] || "").split(",").each do |path| path = path.strip top.download(File.join(current_path, path), path) end end end # Capistrano assumes assets are placed under public/ but static or PHP sites # usually don't have such a separate directory for assets, since they're made of # such files. Accommodate to its default behaviour by symlinking appropriately. def root_contains_assets! after('deploy:finalize_update') do run %w(images stylesheets javascripts).map { |dir| "ln -ns ../#{dir} #{latest_release}/public/#{dir}" }.join('; ') run "ln -ns public/system #{latest_release}/system" end end