键突出显示:
git push
> Heroku使用BuildPacks(用于依赖关系管理,构建和运行您的项目)来管理项目。 它支持许多语言,并且可以自动检测项目类型。第三方Build Packs处理不支持的语言或构建工具。Procfile
特别感谢Matthew Wilkin的宝贵同行评审。
Procfile
本指南解释了Heroku及其Web应用程序部署过程。
git push
操作。 免费的层可以轻松且无成本成本的初始部署(受流量限制)。
遵循本指南,请确保您有:
heroku工具belt(命令行实用程序)。git push
>
已安装和配置的git。 (建议熟悉git。)
如果您有一个现成的项目,请跳过下一节,然后继续“创建Heroku项目”。
示例项目:
>
创建一个项目目录(例如,
:
:
myproject
<code>/myproject /templates index.html app.py requirements.txt</code>
>通过运行
并访问app.py
。
import os import flask app = flask.Flask(__name__) @app.route("/") def index(): return flask.render_template("index.html") if __name__ == "__main__": app.run(port=os.environ.get('PORT', '5000'))
>
git init
heroku create
(或指定名称)。 这会生成一个名称,URL和GIT存储库,并初始化Heroku Remote存储库。heroku create myproject
理解构建包:
> Heroku使用BuildPacks来管理项目。 这些提供了依赖检索,构建和执行的说明。 有几种语言的官方构建包(Node.js,Ruby,Java,Clojure,Scala,Php,Python,GO)。 Heroku会根据约定自动检测项目类型(例如,对于Python)。 第三方Build Packs支持其他语言或构建工具。
requirements.txt
Heroku使用A来确定运行什么。 对于简单的Web应用程序,添加A
,其中包含以下内容:>
Procfile
Procfile
(为了提高性能,请考虑gunicorn:将其添加到
<code>/myproject /templates index.html app.py requirements.txt</code>
。)requirements.txt
>
web: gunicorn app:app -b 0.0.0.0:$PORT
Procfile
部署项目:
添加并提交:
Procfile
git add Procfile && git commit -m "Added Procfile"
git push heroku master
>附加的heroku命令:
:设置持续的配置值。
heroku config:set MY_ENV_VARIABLE=some_value
:列表应用程序版本。heroku ps:scale web=5
:回到特定版本。heroku releases
:删除最新版本。heroku rollback <release_identifier></release_identifier>
这些也可以通过Heroku仪表板进行管理。heroku rollback
常见问题(常见问题解答):以上是部署到Heroku:简介 - sitepoint的详细内容。更多信息请关注PHP中文网其他相关文章!