简体   繁体   中英

How do I prevent capistrano from overwriting files uploaded by users in their own folders?

I'm using Capistrano and git to deploy a RoR app. I have a folder under which each user has their own folder. When a user uploads or saves a file, it is saved in their own folder.

When I deploy new versions of the code to the server, the user files and folders are overwritten with what's on my dev machine.

Is there a way to ignore some folders in capistrano, like we do in git? This post - http://www.ruby-forum.com/topic/97539 - suggests using symlinks and storing the user files in a shared folder. But it's an old post, so I'm wondering if there is a better way to do it now.

Also, does anyone know of any good screencasts/tutorials to recommend for using RoR+git+capistrano?

Thanks.

You should move the user's folders outside of Capistrano's releases directory. The usual approach is to have Capistrano create symbolic links to the directories that should be preserved across deployments.

Here's an example from my Rails blog application's config/deploy.rb whereby files for download within blog posts and images used within posts are stored in a shared directory:

after :deploy, 'deploy:link_dependencies'

namespace :deploy do
  desc <<-DESC
    Creates symbolic links to configuration files and other dependencies
    after deployment.
  DESC
  task :link_dependencies, :roles => :app do
    run "ln -nfs #{shared_path}/public/files #{release_path}/public/files"
    run "ln -nfs #{shared_path}/public/images/posts #{release_path}/public/images/posts"
  end
end

This is too late but I ran into this problem. I use rails 5 and capistrano 3.6. I solved this problem by creating symlink to shared folder.

You might already have this line in your deploy.rb

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle}

If you want to save user's images in public/images/user_images and symlink it to shared folder then add the folder name with a space (like this):

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/images/user_images}

Now run cap production deploy and you should be able to access the images in shared folder.

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