Multiple app environments on the same machine - settings & more

1 view
Skip to first unread message

adam

unread,
Oct 15, 2007, 2:07:36 PM10/15/07
to Django users
Hello Djangonauts,
First of all let me say I'm relatively new to Django and Python.
The problem I came across is how to setup multiple (two, to be
precise) enviroments for my Django app on one physical machine runnig
mod_python. The development environment is set up locally of course.

The idea is I would like to set up a production (prod) and pre-
production (preprod) and have preprod updated and unit tests run
everytime I commit changes to the SVN repo from my local machine (this
can be easily done with svn-hooks).

No problems so far, however what worries me is how to solve the
settings riddle - I would like to have them dynamically imported
depending of which environment (in this case it's simply another
directory on my webserver) it is run on.

So I had the concept to tag each environment with some marker file
like "__DEV", "__PREPROD", "__PROD" and import specific settings from
inside the main settings.py, depending on which tag-file exists in my
cwd. Didn't succed, but wait, there's more. As I said, each
environment is configured to different directory, so I have symlinks
to site-packages/myapp for PROD (which is myapp.com:80) and site-
packages/myapp_preprod for PREPROD (myapp.com:8080).
Then I realised, that even if I get the dynamic-import issue solved,
the preprod app will work with hardcoded "myapp." module instead of
"myapp_preprod." for views dispatching (urls.py).

Are there any hacks or, preferably, some simple and obvious
solutions ;-) to accomplish my goal?
Much love for your feedback.

Take care,
Adam

RajeshD

unread,
Oct 15, 2007, 4:15:54 PM10/15/07
to Django users

> The idea is I would like to set up a production (prod) and pre-
> production (preprod) and have preprod updated and unit tests run
> everytime I commit changes to the SVN repo from my local machine (this
> can be easily done with svn-hooks).
>
> No problems so far, however what worries me is how to solve the
> settings riddle - I would like to have them dynamically imported
> depending of which environment (in this case it's simply another
> directory on my webserver) it is run on.
>
> So I had the concept to tag each environment with some marker file
> like "__DEV", "__PREPROD", "__PROD" and import specific settings from
> inside the main settings.py, depending on which tag-file exists in my
> cwd. Didn't succed, but wait, there's more. As I said, each
> environment is configured to different directory, so I have symlinks
> to site-packages/myapp for PROD (which is myapp.com:80) and site-
> packages/myapp_preprod for PREPROD (myapp.com:8080).
> Then I realised, that even if I get the dynamic-import issue solved,
> the preprod app will work with hardcoded "myapp." module instead of
> "myapp_preprod." for views dispatching (urls.py).
>
> Are there any hacks or, preferably, some simple and obvious
> solutions ;-) to accomplish my goal?

May be this is simple enough (if I understand your problem
correctly ;)

1. Don't add myapp_* to site-packages at all. Instead keep them in two
directory roots say /home/apps/prod and /home/apps/preprod. Similarly,
you can have two different settings files for the two environments.

2. In your Apache vhost config for myapp.com:80, add /home/apps/prod
to the PYTHONPATH setting. And, for myapp.com:8080, add /home/apps/
preprod.

See these two sections in the Django deployment documentation:
http://www.djangoproject.com/documentation/modpython/#basic-configuration
http://www.djangoproject.com/documentation/modpython/#multiple-django-installations-on-the-same-apache

Jeremy Dunck

unread,
Oct 15, 2007, 4:42:18 PM10/15/07
to django...@googlegroups.com
On 10/15/07, RajeshD <rajesh...@gmail.com> wrote:
>
> 1. Don't add myapp_* to site-packages at all. Instead keep them in two
> directory roots say /home/apps/prod and /home/apps/preprod. Similarly,
> you can have two different settings files for the two environments.
>
> 2. In your Apache vhost config for myapp.com:80, add /home/apps/prod
> to the PYTHONPATH setting. And, for myapp.com:8080, add /home/apps/
> preprod.

+1
If you're concerned about sharing site-packages and similar between
the envs, have a look at virtualenv, too. (It supercedes workingenv.)
http://pypi.python.org/pypi/virtualenv/

Reply all
Reply to author
Forward
0 new messages