How to deploy Django to a production server without mercurial files?

I am originally a .NET developer, and when we had to release software from Visual Studio, we had to switch it to release mode to make sure that the debug hooks were removed and the repository files were left behind. The end result was a clean set of files ready to go into production.

After switching to Django and working with it for almost three months, I am now ready to deploy the first application. I have read quite a lot about this. I know how to configure debugging to False and have a production_setting.py file and how to deploy from WSGI to Apache.

But something that I still do not understand is a good process to release.

With what I know now, I would do the following for release:

  • Copy all files manually to the download directory (except for hidden directories containing mercury).
  • Zip them all
  • sending them through SCP to Ubuntu server
  • Server login
  • Extract a zip file and put everything in place
  • Change setting_production.py and enter credentials

Is this a healthy process to deploy Django? :)
FYI I am using Aptana Studio 3.2.1

Thanks for any advice.

+4
source share
2 answers

You can see Fabric ; the documentation describes it as

... a Python library (2.5 or higher) and a command-line tool to optimize the use of SSH for application deployment or system administration tasks.

He is able to do whatever you want.

Your β€œdeploy” task will probably have several subtasks ( _upload_tar_from_hg() , _migrate() , etc.), but the overall picture will look something like this:

 from fabric.api import * env.release_name = 'foo_bar-1.0' env.deployment_path = '/var/www/django/%s' % env.release_name def deploy(): local('hg archive -t tgz $s.tar.gz' % env.release) put('%s.tar.gz' % env.release, env.deployment_dir) run('cd %s && tar -xzvf %s.tar.gz' % (env.deployment_path, env.release)) local('rm %s.tar.gz' % env.release) run('cd %s/%s && ln -s settings_production.py settings.py' % (env.deployment_path, env.release)) 

This depends on having a separate settings_production.py control in the source, which may not be acceptable. The fabric can find and replace in text files, or you can combine parameters using a local_settings.py .

Go to the Fabric tutorial to fill in the blanks (for example, specify connection details for your server. Once you are configured, just run

 fab deploy 

and the process should run automatically.

NB creating an archive from Mercurial without hg metadata is done in one step with the hg archive command)

+2
source

Configure the remote Mercurial repo on the target server. Using SSH keys with the user "hg" is usually the safest way, since you can simply restrict access to the shell of this user and allow him access to the repo.

Click on this repo and use the post-receive hook to check your push to the folder your web server will work with (and restart the web server if necessary).

You can also put a condition in your settings file, which checks whether the application is on a working server (for example, check the file or environment variable) and load the appropriate settings (settings_prod.py or settings_dev.py)

+1
source

All Articles