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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With