Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 901
DevanB Avatar asked Oct 15 '13 16:10

DevanB


2 Answers

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
like image 157
jvperrin Avatar answered Nov 01 '22 06:11

jvperrin


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.

like image 27
DavidA26 Avatar answered Nov 01 '22 06:11

DavidA26