开发者

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

开发者 https://www.devze.com 2022-12-25 19:04 出处:网络
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.

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
  • To answer your second question, I recommend PeepCode and Railscasts


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消