How to configure .txt requirements file for multiple environments?

I have two branches: Development and Production. Everyone has addictions, some of which are different. Development indicates dependencies that are themselves in the development process. Similarly for production. I need to deploy to Heroku, which expects the dependencies of each branch in a single file called "requirements.txt".

What is the best way to organize?

What I was thinking:

  • Maintain separate requirements files, one in each branch (you need to survive frequent mergers!)
  • Tell Heroku which requirements file I want to use (environment variable?)
  • Record deployment scripts (create temp branch, modify requirements file, commit, expand, delete temp branch)
+61
python deployment heroku requirements.txt
Jul 23 '13 at 7:23
source share
1 answer

You can cascade your requirements files and use the -r flag to tell pip to include the contents of one file in another. You can sort your requirements into hierarchies of hierarchical folders as follows:

`-- django_project_root |-- requirements | |-- common.txt | |-- dev.txt | `-- prod.txt `-- requirements.txt 

The contents of the files will look like this:

common.txt:

 # Contains requirements common to all environments req1==1.0 req2==1.0 req3==1.0 ... 

dev.txt:

 # Specifies only dev-specific requirements # But imports the common ones too -r common.txt dev_req==1.0 ... 

prod.txt:

 # Same for prod... -r common.txt prod_req==1.0 ... 

Outside of Heroku, you can configure these environments:

 pip install -r requirements/dev.txt 

or

 pip install -r requirements/prod.txt 

Since Heroku looks specifically for "requirements.txt" at the root of the project, it should just display prod, for example:

requirements.txt:

 # Mirrors prod -r requirements/prod.txt 
+110
Dec 21 '13 at 14:30
source share



All Articles