【问题标题】:Heroku, Middleman, and Contentful: Rebuilding on webhookHeroku、Middleman 和 Contentful:在 webhook 上重建
【发布时间】:2016-02-19 05:01:14
【问题描述】:

我在 Heroku 上运行一个中间人站点,并使用 Contentful 来管理内容。我想使用 Contentful 的 webhook,并已将我的应用设置为使用 contentful_middleman gem 的新 webhook 选项(在 master 分支上)。

它通过在“/receive”上收到 webhook 通知时运行“middleman contentful --rebuild”来重建资产。

由于它的临时文件系统,这个流程在 heroku 上注定要失败吗?从下面的日志来看,似乎是这样。

如果是这样,是否有一种 Heroku 友好的方式可以在中间人应用程序启动后重建它?或者我是否需要切换平台才能以这种方式使用内容丰富的 webhook?

2015-11-16T21:42:05.776622+00:00 app[web.1]: 缓存: [POST /receive] pass 2015-11-16T21:42:35.818683+00:00 heroku[router]: at=info method=POST path="/receive" host=www.mysite.com request_id=some_id fwd="ip, another ip" dyno= web.1 连接=0ms 服务=13ms 状态=405 字节=367 2015-11-16T21:42:35.849264+00:00 app[web.1]:/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:203:in each' 2015-11-16T21:42:35.849253+00:00 app[web.1]: cache error: Read-only file system - /var/cache 2015-11-16T21:42:35.849435+00:00 app[web.1]: cache: [POST /receive] pass 2015-11-16T21:42:35.849281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/thread_pool.rb:104:incall ' 2015-11-16T21:42:35.849268+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/storage.rb :37:在create_store' 2015-11-16T21:42:35.849270+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:149:ininvalidate' 2015-11-16T21:42:35.849279+00:00 app[web.1]:/app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/configuration.rb:51 :在call' 2015-11-16T21:42:35.849265+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:203:inmkdir_p' 2015-11-16T21:42:35.849257+00:00 app[web.1]:/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:242:in fu_mkdir' 2015-11-16T21:42:35.849267+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/metastore.rb:261:innew ' 2015-11-16T21:42:35.849277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb :51:in call' 2015-11-16T21:42:35.849280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/server.rb:262:inblock in run' 2015-11-16T21:42:35.849256+00:00 app[web.1]:/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:242:in mkdir' 2015-11-16T21:42:35.849259+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:219:inblock (2 级)在 mkdir_p' 2015-11-16T21:42:35.849266+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/metastore.rb :218:in initialize' 2015-11-16T21:42:35.849280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/server.rb:375:inprocess_client' 2015-11-16T21:42:35.849263+00:00 app[web.1]:/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:217:in reverse_each' 2015-11-16T21:42:35.849263+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:217:inblock在 mkdir_p' 2015-11-16T21:42:35.849269+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/storage.rb :18:in resolve_metastore_uri' 2015-11-16T21:42:35.849276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:incall!' 2015-11-16T21:42:35.849282+00:00 app[web.1]:/app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/thread_pool.rb:104 :在block in spawn_thread' 2015-11-16T21:42:35.849267+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/metastore.rb:261:inresolve' 2015-11-16T21:42:35.849269+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb :34:在metastore' 2015-11-16T21:42:35.849278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-ssl-1.4.1/lib/rack/ssl.rb:27:incall' 2015-11-16T21:42:35.849279+00:00 app[web.1]:/app/vendor/bundle/ruby/2.0.0/gems/puma-2.11.3/lib/puma/server.rb:507 :in `handle_request'

【问题讨论】:

    标签: heroku middleman contentful


    【解决方案1】:

    遗憾的是,如果不进行新的推送,就无法更新 Heroku 上的静态站点。正如您所说,这是 Heroku 本身的限制。

    替代方案是:

    • Netlify(如其他回复中所述)

    • GitHub 页面

    • 锻造

    • 可能还有其他静态站点主机...

    我只测试了 GitHub Pages,而其他人已经知道被其他人使用,使用一种 hackish 但有效。

    让我继续解释:

    1. 让您的预览服务器在本地运行。

    2. 运行ngrok http $SOME_FREE_PORT

    3. 设置 webhook 以定位 $YOUR_NGROK_URL:$SOME_FREE_PORT/receive

    4. 让您的 /build 目录托管一个新的 Git 存储库,其中包含一个指向 GitHub 页面的 pages 远程

    5. 目前 Webhook 控制器不可配置(但将在未来的版本中)。同时,您可以执行以下操作:

        module ContentfulMiddleman
          class WebhookHandler
             def perform(*)
               super
               rebuild_and_push = <<-BASH
                 bundle exec middleman contentful --rebuild && \
                 bundle exec middleman build && \
                 cd build && \
                 git commit -ca "Webhook Triggered Rebuild" && \
                 git push pages master
               BASH
               system(rebuild_and_push)
             end
           end
         end
    

    如果您自动推送到 Heroku 而不是 GitHub Pages,那么同样的工作流程也适用于 Heroku。

    希望这会有所帮助。

    如果可能,您能否在我们的GitHub repo 上提出问题,以便我们为此用例添加适当的教程并获得有关自定义 Webhook 处理程序的提醒?

    【讨论】:

    【解决方案2】:

    在这方面我远不及你的水平,也没有测试过,但在设置中间人应用程序之前,我一直在寻找类似的解决方案。我遇到了这篇使用 Netlify 的帖子:http://netengine.com.au/blog/simple-static-sites/

    Netlify 会自动托管该网站,但您也可以将构建过程配置为在其他地方部署。

    再一次,我是这方面的初学者,但希望它有一些答案......

    编辑 如果你得到这个工作,我很想听听如何......

    【讨论】:

      【解决方案3】:

      我强烈建议您转至 Netlify。它已经内置了 webhook,并将生成一个可以添加到 Contentful 的 URL。每当在 Contentful 上发布新帖子时,都会通知 Netlify 并运行以下构建命令...

      middleman contentful --rebuild; middleman build --verbose
      

      我已经为我正在运行的设置公开了 repo,它目前仍在暂存中,而我使用 Middleman v4 进行了更多测试,并且 Contentful gem 稍微过时了,因为它是 v4 的一个分支。但它应该可以帮助您进行设置。

      https://github.com/thisiscapra/thisiscapra.com/tree/staging

      【讨论】:

        猜你喜欢
        • 2016-04-11
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-31
        • 1970-01-01
        • 2017-11-06
        • 2021-05-22
        相关资源
        最近更新 更多