简体   繁体   中英

Prevent certain folder in public folder from being removed capistrano rails

I have an app that users upload images and they are stored, via CarrierWave, to the public folder, in a folder named uploads/images/.

I just noticed that since my most recent deploy, the uploads (and images) folder(s) is no longer there.

Could it be removing the folder and files on the production server when I deploy with Capistrano?

How can I tell it to keep the same public/uploads folder through all deploys?

Thanks Stack!

I would recommend making a capistrano task that creates a symlink to the shared folder. The symlink will act as a link to the directory, so all your upload storage/retrieval code will work as normal.

Capistrano task example:

before "deploy:restart", :symlink_directories
task :symlink_directories do
  run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end

I would like to update this answer for those looking to do the same with Capistrano v3.9.1

In your deploy.rb file, you can add the following

set :linked_dirs,  %w{public/uploads/}

As in the answer above, this symlinks directories into the release during deployment.

Ideal for directories such as upload where we do not want to overwrite the contents.

For a full list of variables that you can "set" see the capistrano docs here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM