繁体   English   中英

如何防止capistrano覆盖用户在自己的文件夹中上传的文件?

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

我正在使用Capistrano和git来部署RoR应用程序。 我有一个文件夹,每个用户都有自己的文件夹。 当用户上传或保存文件时,它将保存在自己的文件夹中。

当我将新版本的代码部署到服务器时,用户文件和文件夹将被我的开发机器上的内容覆盖。

有没有办法忽略capistrano中的某些文件夹,就像我们在git中那样? 这篇文章 - http://www.ruby-forum.com/topic/97539-建议使用符号链接并将用户文件存储在共享文件夹中。 但这是一个老帖子,所以我想知道现在是否有更好的方法。

另外,有没有人知道任何好的截屏/教程推荐使用RoR + git + capistrano?

谢谢。

您应该将用户的文件夹移到Capistrano的releases目录之外。 通常的做法是让Capistrano创建指向应在部署中保留的目录的符号链接。

以下是我的Rails博客应用程序的config/deploy.rb的一个示例,其中博客文章中下载的文件和帖子中使用的图像存储在shared目录中:

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

这太晚了,但我遇到了这个问题。 我使用rails 5和capistrano 3.6。 我通过创建符号链接到共享文件夹解决了这个问题。

您可能已在deploy.rb中拥有此行

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

如果要将用户的图像保存在public / images / user_images中并将其符号链接到共享文件夹,则使用空格添加文件夹名称(如下所示):

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

现在运行cap production deploy ,您应该能够访问共享文件夹中的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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