使用docker,在Heroku上的scrapy飞溅
我有一个scrapy蜘蛛,使用在Docker上运行的本地主机:8050来渲染JavaScript之前刮。 我想在heroku上运行这个,但不知道如何configurationheroku启动泊坞窗在运行我的网站之前运行splash:scrapy crawl abc dyno。 任何指南非常感谢!
从我所收集的你所期望的:
- 通过Docker容器在Heroku上运行的实例
- 您的Web应用程序(Scrapy蜘蛛)在Heroku dyno中运行
飞溅实例
- 确保您可以安装
docker
CLI和heroku
CLI - 正如在Heroku的容器registry中看到的- 推送现有的图像 :
- 确保已安装
docker
CLI和heroku
CLI -
heroku container:login
-
docker tag scrapinghub/splash registry.heroku.com/<app-name>/web
-
docker push registry.heroku.com/<app-name>/web
- 要testing应用程序:
heroku open -a <app-name>
。 这应该允许你在Heroku主机的端口8050上看到这个应用程序名称的Splash UI。- 您可能需要确保
$PORT
被适当设置,因为EXPOSE
configuration不受尊重( https://devcenter.heroku.com/articles/container-registry-and-runtime#dockerfile-commands-and-runtime )
- 您可能需要确保
- 确保已安装
运行Dyno Scrapy Web应用程序
- 将您的应用程序configuration为指向
<app-host-name>:8050
。 Scrapy蜘蛛现在应该能够请求以前运行的Splash实例。
运行在同样的问题。 最后,我成功地在Heroku上部署了splash docker镜像。 这是我的解决scheme:我从github克隆了splashproyect并更改了Dockerfile。
- 由于Heroku不支持,因此删除了EXPOSE命令
- 用CMD命令取代了ENTRYPOINT。
CMD python3 / app / bin / splash –proxy-profiles-path / etc / splash / proxy-profiles –js-profiles -path / etc / splash / js-profiles –filters-path / etc / splash / filters – -lua-package-path /etc/splash/lua_modules/?.lua –port $ PORT
注意我添加了选项–port = $ PORT。 这只是在Heroku指定的端口而不是默认的(8050)
一个叉到这个项目在这里改变它的可用性你只需要build立docker的形象,并把它推到heroku的registry,就像你以前做的那样。 您可以先在本地进行testing,但运行泊坞窗时必须传递环境variables“PORT”
sudodocker运行-p 80:80 -e PORT = 80 mynewsplashimage