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

时间:2022-11-09 07:25:39

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.

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

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.

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

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

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

Thanks.

2 个解决方案

#1


11  

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.

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

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:

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

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
  • 要回答第二个问题,我建议使用PeepCode和Railscasts

#2


0  

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.

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

You might already have this line in your deploy.rb

您可能已在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):

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

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.

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

#1


11  

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.

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

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:

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

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
  • 要回答第二个问题,我建议使用PeepCode和Railscasts

#2


0  

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.

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

You might already have this line in your deploy.rb

您可能已在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):

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

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.

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