在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上點選一鍵部署,最後成功運作起來了。
本文作者:佚名
來源:51cto