ruby-on-rails – 替代Heroku的AssetSync gem

最近,在我最近部署到Heroku时,我收到了警告 advising not to use AssetSync.
remote: ###### WARNING:
remote:        You are using the `asset_sync` gem.
remote:        See https://devcenter.heroku.com/articles/please-do-not-use-asset-sync for more information.

我们试图通过使用AssetSync解决的原始问题是我们的应用程序中的大型资产导致了巨大的段塞大小.在Heroku允许我们的300MB中,我们可能使用接近230MB – 尽管我们的git repo只有80MB左右.

我们通过使用AssetSync将所有已编译资产同步到通过Cloudfront提供的S3存储桶来解决此问题.在AssetSync运行之后,我们有一个钩子可以删除所有预编译资产以减少段塞大小.基本上,slug编译期间的工作流程如下所示:

>让Heroku预编译资产
> AssetSync将所有已编译的资产同步到S3
>删除已编译资产的所有本地副本

链接文章争论了一些关于它为什么不好以及使用什么的点.

Using Asset Sync can cause failures. It is difficult to debug,
unnecessary,and adds extra complexity. Don’t use it. Instead,use a
CDN.

[…]

You should Now use a CDN instead. Rather than
copying your assets over to S3 after they are precompiled,the CDN
grabs them from your website. Here are some reasons why that’s better.

Canonical assets

[…] It allows you to have single,authoritative places where you
store information. If you need to change that information,you only
need to change it in one place. […] What happens if someone has a
Failed deploy after assets get synced? What if someone modifies a file
in the S3 bucket? Instead of fixing one copy of assets,Now you must
fix two.

Deploy determinism

If you’re debugging inside of a dyno with heroku run bash and you run
rake assets:precompile this doesn’t just modify your local copy. It
actually modifies the copy on S3 as well. […] The sync part of
asset_sync can also fail if there’s a glitch in the network. What if
you only write part of a file,or only half of your assets are synced?
These things happen.

虽然我同意他们的观点,但问题仍然存在:当预编译资产存储在slug中时,部署Heroku应用程序的推荐方法是什么?

解决方法

问题是哪些资产文件使slu the巨大?

认情况下,Rails资产管道只应用于小型和有限的内部资产(如JS,CSS,一些徽标等).

将Rails资产存储为大量外部或大文件并不是一个好主意,除了管道之外还有很多原因(就像它使你的Git目录一样大).

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...