2010-04-03 75 views
7

我正在使用Capistrano和git来部署RoR应用程序。我有一个文件夹下每个用户有自己的文件夹。当用户上传或保存文件时,它会保存在他们自己的文件夹中。如何防止capistrano覆盖用户上传自己文件夹中的文件?

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

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

此外,有没有人知道任何良好的屏幕录像/教程推荐使用RoR + git + capistrano?

谢谢。

回答

10

您应将用户的文件夹移动到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 
+0

谢谢约翰,它是符号链接。 – 2010-04-03 10:48:53

0

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

如果你想保存了public/images/user_images用户的图像,并将其符号链接到共享文件夹,然后用空间添加的文件夹名称(您可能已经有这条线在你的deploy.rb

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

像这样):

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

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