[英]Why does Rake task enhancement differ between my local environment and when deploying to Heroku Cedar?
I have this in lib/tasks/foo.rake : 我在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. 当我运行
rake assets:precompile
在本地rake assets:precompile
,两个消息都被打印出来。
When I push to heroku, only the nondigest message is printed. 当我推送到heroku时,只打印非自动消息。 However, according to the buildpack , the push is executing the exact same command as I am locally.
但是, 根据buildpack ,push正在执行与本地完全相同的命令。
Why does the enhancement to the base assets:precompile case not work on heroku but does work locally? 为什么基础资产的增强:预编译案例在heroku上不起作用但在本地工作?
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. 我一直在调查这个问题,我发现
assets:precompile
的行为assets:precompile
取决于RAILS_ENV
和RAILS_GROUPS
是否设置都在本地查看。
# 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. 问题来自https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake在
invoke_or_reboot_rake_task
方法中,如果你替换Rake::Task[task].invoke
line使用ruby_rake_task task
然后它就像你期望的那样工作。 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. 由于两个变量都是在Heroku构建包中设置的,因此您可以在不设置GROUP和ENV设置的情况下创建自定义构建包,但我认为这样做太过分了。 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. 在这种情况下,您应该能够增强
assets:precompile:primary
或assets:precompile:all
并实现与您期望的意图类似的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.