1

我在 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]:cache:[POST /receive] pass 2015-11-16T21:42:35.818683+00:00 heroku[router]:at=info 方法=POST path="/receive" host=www.mysite.com request_id=some_id fwd="ip, another ip" dyno=web.1 connect=0ms service=13ms status=405 bytes=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 应用程序 [web.1]:/app/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/storage.rb:37:increate_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:in无效' 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:in 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:infu_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:in新的' 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 levels) in 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 in 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:inresolve_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:in称呼!' 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 :in 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:in 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'

4

3 回答 3

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 存储库,该存储库有一个pages远程指向 GitHub 页面

  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 存储库上打开一个问题,以便我们为此用例添加适当的教程并获得有关自定义 Webhook 处理程序的提醒?

于 2015-12-21T12:18:12.583 回答
0

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

middleman contentful --rebuild; middleman build --verbose

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

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

于 2015-12-20T11:03:50.523 回答
0

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

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

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

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

于 2015-12-11T21:14:09.203 回答