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

前端之家收集整理的这篇文章主要介绍了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目录一样大).

猜你在找的Ruby相关文章