首页 文章

Heroku,Middleman和Contentful:在webhook上重建

提问于
浏览
1

我在Heroku上运行一个Middleman网站,并使用Contentful来管理内容 . 我想使用Contentful的webhooks,并设置我的应用程序以使用contentful_middleman gem的新webhook选项(在主分支上) .

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

由于其短暂的文件系统,这个流程注定在heroku上注定了吗?看起来好像,从下面的日志中可以看出来 .

如果是这样,有没有一个heroku友好的方式来重建一个中间人应用程序已经推出?或者我是否需要切换平台才能以这种方式使用contenful 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 method = 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:in call'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:in 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:in invalidate'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:in mkdir_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:in new'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:in block 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:in block(2个级别)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:in process_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:in block 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: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:in call!' 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:in resolve'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: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/server.rb:507:in `handle_request'

3 回答

  • 1

    我强烈建议搬到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

  • 0

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

    替代方案是:

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

    • GitHub页面

    • 锻造

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

    我只测试了GitHub页面,而其他人已经被其他人使用过,使用了一种hackish但工作 .

    让我来解释一下:

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

    • 运行 ngrok http $SOME_FREE_PORT

    • 设置webhooks以定位 $YOUR_NGROK_URL:$SOME_FREE_PORT/receive

    • 让你的 /build 目录托管一个新的Git Repo,它有一个指向GitHub Pages的 pages 遥控器

    • 目前,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页面,这个工作流程可以应用于Heroku .

    希望这可以帮助 .

    如果可能,您可以在GitHub repo上打开一个问题,以便我们可以为此用例添加适当的教程并获取Custom Webhook处理程序的提醒吗?

  • 0

    我测试了它,但在设置中间人应用程序之前我一直在寻找类似的解决方案 . 我遇到过使用Netlify的帖子:http://netengine.com.au/blog/simple-static-sites/

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

    再说一次,我非常喜欢这个,但希望它有一些答案......

    Edit 如果你有这个工作,我很想听听......

相关问题