简体   繁体   English

Capistrano的Carrierwave文件

[英]Carrierwave files with Capistrano

I'm using rails 3.2 with asset and carrierwave for upload some images, they store in /public/uploads/photo/..... but when I do a cap:deploy (with capistrano) my current directory application doesn't contain the files I uploaded, because capistrano make a new version .... 我正在使用带有资产和载波的rails 3.2来上传一些图像,它们存储在/ public / uploads / photo / .....但当我执行上限时:部署(使用capistrano)我的当前目录应用程序不包含我上传的文件,因为capistrano制作了新版本....

=== Update === ===更新===

After all I use this : 毕竟我用这个:

inside :deploy namespace inside:deploy命名空间

   task :symlink_uploads do
     run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"
   end

and after: 之后:

after 'deploy:update_code', 'deploy:symlink_uploads'

=== Re Update === ===重新更新===

The solution of @tristanm is the best way to solve this. @tristanm的解决方案是解决这个问题的最佳方法。

How about this: 这个怎么样:

# config/deploy.rb
set :shared_children, shared_children + %w{public/uploads}

:shared_children defaults to %w(public/system log tmp/pids) so we're just expanding this list. :shared_children默认为%w(public/system log tmp/pids)因此我们只是扩展此列表。

EDIT: 编辑:

Don't forget to run cap deploy:setup after changing :shared_children so that the new targets are created under shared . 不要忘记运行cap deploy:setup更改后cap deploy:setup :shared_children以便在shared下创建新目标。

EDIT Capistrano 3: 编辑Capistrano 3:

Capistrano 3 uses the linked_dirs setting and doesn't specify public/system as a default anymore. Capistrano 3使用linked_dirs设置,不再将public/system指定为默认值。

set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}

With Capistrano 3 and without needing to redeploy. 使用Capistrano 3而无需重新部署。

Like @tristanm mentioned add this to your config/deploy.rb 就像@tristanm提到的那样,将它添加到你的config / deploy.rb中

# config/deploy.rb
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}

To have capistrano create shared/public/uploads 让capistrano创建共享/公共/上传

cap deploy:check:linked_dirs

Now cap can create the symlink 现在cap可以创建符号链接

cap deploy:symlink:shared

Finally, if you have backups of the uploads you can put them in shared/public/uploads/ and they should work without needing to redeploy. 最后,如果你有上传的备份,你可以将它们放在shared / public / uploads /中,它们应该无需重新部署即可运行。

Capistrano creates new directory for every deploy. Capistrano为每个部署创建新目录。

There are some exceptions to it. 它有一些例外。 For example, the log files are shared between the deployment directories because they are just symlinks. 例如,日志文件在部署目录之间共享,因为它们只是符号链接。 You have to create a symlink for public/uploads as well. 您还必须为公共/上传创建符号链接。

Here is the command: 这是命令:

run <<-CMD
  rm -rf #{latest_release}/public/uploads &&
  ln -s #{shared_path}/uploads #{latest_release}/public/uploads
CMD

Go to your app server shared folder and create an uploads directory. 转到您的应用服务器共享文件夹并创建一个上传目录。

mkdir uploads mkdir上传

In your deploy.rb file insert these codes under deploy namespace 在deploy.rb文件中,在deploy命名空间下插入这些代码

task :symlink_uploads do 任务:symlink_uploads做

run "rm -rf #{latest_release}/public/uploads && ln -nfs #{shared_path}/uploads #{latest_release}/public/uploads" 运行“rm -rf#{latest_release} / public / uploads && ln -nfs#{shared_pa​​th} / uploads#{latest_release} / public / uploads”

end 结束

after 'deploy:update_code', 'deploy:symlink_uploads' 在'deploy:update_code'之后,'deploy:symlink_uploads'

Now delete the old files present already as they won't work. 现在删除已存在的旧文件,因为它们不起作用。 Upload a new file and cap deploy your app again. 上传新文件并再次部署您的应用。 It should work now. 它现在应该工作。

Using Capistrano 3, I just added this line to my config/deploy.rb 使用Capistrano 3,我刚刚将此行添加到我的config / deploy.rb中

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

Then, run: 然后,运行:

$ cap production deploy

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

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