如何在部署Heroku时自定义pip的requirements.txt? [英] How to customize pip's requirements.txt in Heroku on deployment?
问题描述
我正在为Heroku部署一个Python Django应用程序,并且我只想在部署到像Heroku这样的特定环境时自定义requirements.txt文件(通过添加具有密码的git支持的依赖项)。我很想在环境变量中设置它,但我不相信pip具有这样的功能。我的想法是使用Heroku提供的一个钩子来放置一个脚本,该脚本将在依赖关系安装之前添加到我的requirements.txt中。这可能吗?
您可以在其他需求文件中包含需求文件。 $ b
#requirements.txt
-r需求/ base.txt
#需求/ base.txt
django == 1.6
#requirements / heroku.txt
-r需求/ base.txt
djpostgresurlthing == 1.0.0
#requirements / dev.txt
-r要求/ base.txt
django-debug-toolbar
我通常在项目的根目录中保留一个 requirements.txt
文件,该文件只包含其他需求文件(通常是prod或基础),并使 requirements /
文件夹与环境特定的东西。所以在本地我会 pip安装-r要求/ dev.txt
和服务器上 pip install -r requirements / prod.txt
对于你的情况与heroku,你需要根requirements.txt为heroku。所以你可以使用这个文件来包含你的heroku需求文件。
$ $ $ $ $ $ $ $# heroku.txt
可能有一些告诉heroku使用不同文件的方法。但这将是一个简单的方法来解决它。
I'm deploying a Python Django app to Heroku, and I'd like to customize the requirements.txt file (by adding a git-backed dependency with password) only when I deploy to certain environments like Heroku. I'd love to set this in an environment variable or something, but I don't believe pip has any functionality like that. My idea was to use a hook that Heroku provides to place a script which would add to my requirements.txt before the dependencies are installed. Is that possible?
You can include a requirements file in another requirements file.
# requirements.txt
-r requirements/base.txt
# requirements/base.txt
django==1.6
# requirements/heroku.txt
-r requirements/base.txt
djpostgresurlthing==1.0.0
# requirements/dev.txt
-r requirements/base.txt
django-debug-toolbar
I typically keep a requirements.txt
file in the root of the project that just includes other requirements files(usually prod or a base) and make a requirements/
folder with environment specific stuff. So locally I'd pip install -r requirements/dev.txt
and on the server pip install -r requirements/prod.txt
.
For your case with heroku, you need the root requirements.txt to be for heroku. So you can just use that file to include your heroku requirements file.
# requirements.txt
-r requirements/heroku.txt
There's probably SOME way to tell heroku to use a different file. But this would be an easy way to get around it.
这篇关于如何在部署Heroku时自定义pip的requirements.txt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!