如何配置 Travis-CI 为 rails 应用程序使用正确的时区? [英] How do I configure Travis-CI to use the correct time zone for a rails app?
问题描述
在我的 application.rb 中,我有
In my application.rb, I have
config.time_zone = "Pacific Time (US & Canada)"
这在开发/测试和生产服务器中正常工作.但是,当我推送到 Travis-CI 时,它似乎已本地化为 UTC,例如 I18n.l Time.now
的输出.
And this works correctly in development/test, and production servers. However when I push to Travis-CI, it appears to be localized to UTC for example the output of I18n.l Time.now
.
Travis-CI ruby/rails 环境有什么不同吗?
Is there something different about the Travis-CI ruby/rails environment?
推荐答案
我设置时区的方式是在 travis.yml 的 before_script 部分
The way I accomplish setting the timezone is in the before_script section of the travis.yml
它们为您提供对运行项目的 VM 的 root 访问权限,因此您只需设置 ruby 使用的操作系统时区:
They give you root access to the VM running your project, so you can simply set the OS timezone that ruby uses:
before_script:
- echo 'Canada/Pacific' | sudo tee /etc/timezone
- sudo dpkg-reconfigure --frontend noninteractive tzdata
如果您愿意,也可以通过在下面添加以下内容来强制更新:
If you wish, you can also force an update by adding this below:
- sudo ntpdate ntp.ubuntu.com
这篇关于如何配置 Travis-CI 为 rails 应用程序使用正确的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!