2

On the production server, I certainly need to have different settings, and are different from local settings.

Our opensource project is hosted on github. Thus the master branch is not production code (at least up to settings config).

Now, we got to host the project (django).. for that, The simplest solution I found is to create a new branch locally, setup production settings, add server git as remote, push that branch to the remote origin.

So, we can merge latest stable release whenever we want into production branch.. easily

But there is some issue in managing files in github..

Say the django settings are provided in "proj/settings.py". As local settings differ between system to system, we created "proj/local_settings.py" to overwrite system specific local settings (say, staticfiles location).. This file is ignored by Git using .gitignore

Now, if we use this file in production branch to config production settings, and as its currently ignored but Git.. we can't use it.

To push local_settings.py to production server from local production branch, we need to remove that location in .gitignore in that particular branch..

All is fine, accepted till here..

Here comes actual issue.

When we want to push new changes to production server, we first got to push them to production-local-branch, then to production server... but now,

.gitignore file changes to as present in release (i.e., local_settings.py is again added)

For this, I have to manually remove local_settings.py in gitignore of production-local-branch every time I merge something into it...

certainly the above all is a big mess..How do I handle it easily

1 Answers1

1

What I'd suggest is to remove from your settings.py any settings that depend on where it is deployed. Put those settings into environment variables. For example:

STATIC_ROOT = os.environ.get('STATIC_ROOT')

then you need to set those environment variables before running the webserver.

On local:

STATIC_ROOT=`pwd`/static python manage.py runserver

On production depends on how you deploy, consult the documentation.

This principle of config into environment variables is exposed in the Twelve Factor App : http://www.12factor.net/config

Ponytech
  • 1,634
  • 14
  • 21