加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 21:12:54 所属栏目:百科 来源:网络整理
导读:最近,在我最近部署到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.
最近,在我最近部署到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目录一样大).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读