简体   繁体   中英

Web app deployment - git environments

I am creating a small commercial web project running Apache/WSGI/Django/MySQL.
I have a development and a production environment and use git and fabric to push/pull modifications.

Now I'd like to be able to test new versions with similar conditions to the production server before making them live.

  • I am thinking of using the same physical server with different URLs and different repositories (is this ok ?).
  • Are there best practices to set up this pre-prod environment as close as possible to the prod ?
  • Should I use the same web server and database server ? In that case how can I manage for example the database name ?

I am working on a similar setup to the one you describe with no major problems. Multiple databases are easily managed in the settings file, I change them based on the root dir name:

ROOTDIR = os.path.abspath(os.path.dirname(__file__))

if ROOTDIR.startswith("dev_"):
    # -------- Developing settings ---------
    DOMAIN_NAME = 'dev.foo.com'
    DATABASES = {
        'default':{
            'ENGINE': 'django.db.backends.postgresql_psycopg2', 
            'NAME': 'development_db',         
            'USER': 'xxxx',          
            'PASSWORD': 'xxxxx',       
            'HOST': 'localhost',         
            'PORT': '',                  
            'OPTIONS': {'autocommit': True,}
        }
    }


elif ROOTDIR.startswith("production_"):
    # --------- Production settings --------
    DEBUG = False
    DOMAIN_NAME = 'production.foo.com'
    TEMPLATE_DEBUG = DEBUG
    DATABASES = {
        'default':{
            'ENGINE': 'django.db.backends.postgresql_psycopg2', 
            'NAME': 'production_db',     
            'USER': 'xxx',           
            'PASSWORD': 'xxx',        
            'HOST': 'localhost',         
            'PORT': '',                 
            'OPTIONS': {'autocommit': True,}
        }
    }
else:
# ....

What you could do is set up the server so each site runs in its own virtualenv http://pypi.python.org/pypi/virtualenv this can work together with apache and wsgi.

See here for example http://www.foxhop.net/django-virtualenv-apache-mod_wsgi (this is with mod_wsgi however)

this way you have full controll of packages installed in each virtualenv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM