如何在coding.net上部署项目 (Flask),coding.netflask


在coding.net上部署一个flask应用的过程记录
  • fork别人的一个flask应用,本地已经跑起来了,现在把它部署到coding上。
  • 想在coding上运行,需要多加一个Procfile文件,官方示例如下

web: gunicorn hello:app -b $VCAPAPPHOST:$VCAPAPPPORT

其中,hello即应用下的主文件,我的是123.py,并且也不需要绑定host和端口,所以我的Procfile文件内容是

web: gunicorn 123:app

  • git push把代码传到coding

  • coding说了

    项目必须使用 Pip 来解决依赖,如果项目目录下没有 requirements.txt 文件,你必须创建一个,否则项目将无法部署。小提示:可以使用 pip freeze > requirements.txt 命令生成 requirements.txt 文件

这里非常的坑,这是之后部署出现的问题

2015-05-09T13:21:40.51+0800 [STG] OUT Could not find a version that satisfies the requirement Werkzeug==0.10.1 (from -r requirements.txt (line 6)) (from versions: 0.1, 0.2, 0.3.1, 0.3, 0.4.1, 0.4, 0.5.1, 0.5, 0.6.1, 0.6.2, 0.6, 0.7.1, 0.7.2, 0.7, 0.8.1, 0.8.2, 0.8.3, 0.8, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6, 0.9) 2015-05-09T13:21:40.51+0800 [STG] OUT Cleaning up... 2015-05-09T13:21:40.57+0800 [STG] OUT Storing debug log for failure in /home/vcap/.pip/pip.log 2015-05-09T13:21:40.61+0800 [STG] OUT Staging failed: Buildpack compilation step failed 2015-05-09T13:21:40.75+0800 [API] ERR Encountered error: Staging error: failed to stage application: 2015-05-09T13:21:40.75+0800 [API] ERR Script exited with status 1

这里原因很明显,平台的pip找不到符合requirements.txt里指定的模块版本来安装,可以看到列出的可用版本低于指定版本,我想问一句,您用的什么pip源啊,该换换了吧!

  • 折腾了一下,找到一个简单方法,把requirements.txt里版本号全删了,

Flask==0.10.1
gunicorn==19.3.0
itsdangerous==0.24
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.10.1

修改成

Flask
gunicorn
itsdangerous
Jinja2
MarkupSafe
Werkzeug

虽然不严谨,但是works。

在coding上点击一键部署,最后成功运行起来了。 flask-deploy

Written on May 9, 2015

相关内容

    暂无相关文章