为什么Rake任务增强在我的本地环境和部署到Heroku Cedar时有所不同? [英] Why does Rake task enhancement differ between my local environment and when deploying to Heroku Cedar?

查看:98
本文介绍了为什么Rake任务增强在我的本地环境和部署到Heroku Cedar时有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 lib / tasks / foo.rake 中找到了这个:

  Rake :: Task增强do 
print>>>>>>>>> hello from precompile
end
Rake :: Task [










$ b $ code>

当我在本地运行 rake资产:预编译时,将打印这两条消息。

当我推送到heroku时,仅打印非摘要消息。但是,根据buildpack ,推送执行与本地完全相同的命令。



为什么对基础资产进行增强:precompile case在heroku上不起作用,但在本地工作?

解决方案

我一直在研究这个问题,并且发现资产的行为:precompile 取决于 RAILS_ENV RAILS_GROUPS 是否都设置或不在本地查看。

 #此工程
→bundle exec rake资产:预编译RAILS_ENV =生产
>>> ;>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile

#这可以工作
→bundle exec rake assets:预编译RAILS_GROUPS = assets
>>>>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile


#这不起作用:'(
→bundle exec rake assets:precompile RAILS_ENV = production RAILS_GROUPS = assets
>>> ;>>>>>> hello from precompile:nondigest

问题来自 https://github.com/rails/如果您替换 Rake中的 invoke_or_reboot_rake_task 方法中的rails / blob / 3-2-stable / actionpack / lib / sprockets / assets.rake :: Task [任务] .invoke ruby​​_rake_task任务行然后它就像你期望的那样工作。为什么会这样,并且没有找到原因。



由于这两个变量都是在Heroku构建包中设置的,因此您可以创建自定义构建包,而无需同时设置GROUP和ENV设置,尽管我认为这是过度杀毒。在这种情况下,您应该能够将增强为sets:precompile:primary assets:precompile:all 并获得与您期望的意图类似的结果。


I have this in lib/tasks/foo.rake:

Rake::Task["assets:precompile"].enhance do
  print ">>>>>>>> hello from precompile"
end
Rake::Task["assets:precompile:nondigest"].enhance do
  print ">>>>>>>> hello from precompile:nondigest"
end

When I run rake assets:precompile locally, both messages are printed.

When I push to heroku, only the nondigest message is printed. However, according to the buildpack, the push is executing the exact same command as I am locally.

Why does the enhancement to the base assets:precompile case not work on heroku but does work locally?

解决方案

i've been looking into this issue and I found out that the behavior of the assets:precompile depending on if RAILS_ENV and RAILS_GROUPS are both set or not take a look at this locally.

  # This works
  → bundle exec rake assets:precompile RAILS_ENV=production
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile

  # This works
  → bundle exec rake assets:precompile RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile
  →

  # This does not work :'(
  → bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  →

The problem comes from https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake in invoke_or_reboot_rake_task method if you replace the Rake::Task[task].invoke line with ruby_rake_task task then it works like you would expect it to. I've been poking around on exactly why this is, and haven't found the reason.

Since both variables are set in the Heroku build pack, you could create a custom build pack without setting both GROUP and ENV settings, though I think that is overkill. In this scenario you should be able to enhance assets:precompile:primary or assets:precompile:all and achieve an outcome similar to your desired intent.

这篇关于为什么Rake任务增强在我的本地环境和部署到Heroku Cedar时有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆