views:

245

answers:

3

I've an issue at the moment where we are running a CMS within a site (browsercms) that lets the user upload files. However, every time I do a deploy Capistrano runs a hard reset thus nuking any uploaded files.

Does anyone have any suggestions as to how to prevent the hard reset, and just do a pull, or a way of moving the uploaded files elsewhere, without having to change the application code?

+2  A: 

This doesn't quite meet your criteria of "without having to change the application code".

However after running into a similar issue I shifted my uploaded image from /public/images to /public/system/images the /public/system directory is not 'versioned' by each capistrano deployment so the images survive.

Could it be the capistrano 'versioning' causing the problem (instead of a git reset)?

waldo
Ah yes, you might be right there. It may be that I need to make the uploads directory a 'shared' one.
Neil Middleton
This is the preferred Capistrano solution, which is why it symlinks current/public/system to shared/system by default. Paperclip and some other plugins store things here by default for that rason, too. AttachmentFu managed models will need the "upload_path" changed per model.
Ian Terrell
A: 

cap deploy calls deploy:update and deploy:restart

deploy:update makes the versioning, copying stuff

deploy:restart does the true restart, overload it at your convenince, usually in your config/deploy.rb file

namespace :deploy do
    desc "Softly restart the server"
    task :restart, :roles => :app, :except => { :no_release => true } do
      my_own.restart_recipe
    end  
end
Fer
A: 

This might not be the right approach.

You should include your 'images' folder in your .gitignore and symlink the $current_release/images folder to $shared/images.

This may be done automatically on every deployment if you put in your deploy.rb:

task :link_imgs do     
  run "ln -s #{shared_path}/photos #{release_path}/photos" 
end    

after "deploy:update_code", :link_imgs

I've done the same with my CMS and it works like a charm

Guillermo