Heroku Pipelines + Amazon Cloudfront 和多个环境

Heroku Pipelines + Amazon Cloudfront and multiple environments

我已经使用 Heroku Pipelines 设置了一个 Rails 应用程序,以便能够自动将我们的暂存环境提升到生产环境。 master push -> CI 运行 -> staging deploy -> production promotion 的工作流程对我们来说非常有效。

我们的资产正在使用 Amazon Cloudfront 进行分发。我为暂存环境和生产环境设置了单独的发行版,我在环境中进行了配置:

# Environment variable configured per environment
config.action_controller.asset_host = ENV['ASSET_HOST']

此设置出现了一个问题。即使我为每个环境配置了 asset_host,资产也在暂存环境中进行了预编译,并且在使用 Heroku Pipelines 进行推广时也将在生产环境中使用。这会导致我们的自定义字体 CORS 出现问题..

我考虑过为多个来源配置一个 Cloudfront 分布,但无法弄清楚。另外,我真的很想保留我们当前的工作流程,因为它为我们启用了 CD。

将暂存环境和生产环境都配置为来源和行为的 Cloudfront 是解决方案。

要实现这一点,asset_host 应该与暂存和生产相同。

Heroku explains这个很好:

For many applications sharing a CDN between staging and production is surprising, however causes no problems. You can manually configure both to have the same “asset_host”. This works because even if the copy of the assets has been modified on the staging app, all assets are fingerprinted, and the “production” app will point browsers at the correct fingerprints. The staging app will serve up to 3 old copies of assets, and the CDN should keep assets cached indefinitely.