资产在 s3 上的 Heroku webpacker - 在清单中找不到资产

Heroku webpacker with assets on s3 - asset not found in manifesst

我在 heroku 上部署了一个带有 webpacker 的 rails 6 应用程序。 public/packs 与 s3 存储桶同步,与 public/assets 相同。 从 public/assets 交付资产有效。但是当我试图打开任何依赖于 public/packs 的东西时,我得到了。

2020-06-04T05:33:03.622234+00:00 app[web.1]: [58f2d221-761b-44ec-807c-6b922342c10b] method=GET path=/teach/organizations format=html controller=OrganizationsController action=index status=500 error='ActionView::Template::Error: Webpacker can't find admin_unify_style.css in /app/public/packs/manifest.json. Possible causes:
2020-06-04T05:33:03.622242+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2020-06-04T05:33:03.622242+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2020-06-04T05:33:03.622244+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2020-06-04T05:33:03.622244+00:00 app[web.1]: Your manifest contains:
2020-06-04T05:33:03.622245+00:00 app[web.1]: {
2020-06-04T05:33:03.622245+00:00 app[web.1]: }

heroku 如何在 heroku 上找到清单。清单包含

"entrypoints": {

    "admin_unify_style": {
        "css": [
            "/packs/css/admin_unify_style-c2ad729a.css"
        ],
        "js": [
            "/packs/js/admin_unify_style-62270c86710162620f91.js"
        ],
        "js.map": [
            "/packs/js/admin_unify_style-62270c86710162620f91.js.map"
        ]

更新一: 它在 heroku 之外的生产环境中工作,并且在云端没有资产

长话短说 - 清单应该在 heroku 上,而资产可以在 s3 上

这是我如何让它工作的 - Heroku、S3、Cloudfront、Webpacker、Rails 6、Sprockets。

  1. 资产已预编译并上传到 s3。 public/assets 和 public/packs 从 repo 中被忽略。
public/assets/*
!public/assets/.sprockets-manifest*
public/packs/*
!public/packs/manifest.json*

但如您所见,清单并非如此。

  1. Cloudfront 已针对生产配置
  config.action_controller.asset_host = "https://blabla.cloudfront.net"
  1. public/assets 和 public/fonts 通过 s3cmd 命令在 s3 上同步。自定义脚本。
  2. 同步到 s3 后,我们将提交清单
if git ls-files -m | grep "public/assets/.sprockets-manifest\|public/packs/manifest.json*"; then
  git add --all public/assets/.sprockets-manifest* -f
  git add --all public/packs/manifest.json* -f
  git commit -m "Autocompiling assets from jenkins"
  git push
fi

通过这种方式,我们在存储库中只有两个清单以及 S3 上的所有资产。 5. 推送到 heroku 就可以了。现在,喜欢魅力