Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django and multi-stage servers

I am working with a client that demands multi-stage server setup: development server, stage server and production/live server.

Stage should be as stable as it can be to test all those new features we develop at the development server and take this to the live server in the end.

We use git and github for version controlling. I use Ubuntu server edition as the OS.

The problem is, I have never working in such multi-stage server plan. What software/projects would you recommend to do a proper way of handling such setup, especially deployment and moving a new feature developed to the stage and then to the live server ?

like image 442
Hellnar Avatar asked Oct 08 '11 23:10

Hellnar


People also ask

Which server is used in Django?

Gunicorn is the recommended HTTP server for use with Django on Heroku (as referenced in the Procfile above). It is a pure-Python HTTP server for WSGI applications that can run multiple Python concurrent processes within a single dyno (see Deploying Python applications with Gunicorn for more information).

Does Django need a web server?

Django, being a web framework, needs a web server in order to operate. And since most web servers don't natively speak Python, we need an interface to make that communication happen. Django currently supports two interfaces: WSGI and ASGI.

How do I run a Django server in production?

If you want to run Django in production, be sure to use a production-ready web server like Nginx, and let your app be handled by a WSGI application server like Gunicorn. If you plan on running on Heroku, a web server is provided implicitly. You don't have to take care of it.


1 Answers

We use two different methods of moving code from environment to environment. The first is to use branches and triggers with our source control system (mercurial in our case, though you can do the same thing with git). The other, is to use fabric, a python library for executing shell code across a number of servers.

Using source control, you can have several main branches, like production development staging. Say you want to move a new feature into staging. I'll explain in terms of mercurial, but you can port the commands over to git and it should be fine.

hg update staging
hg merge my-new-feature
hg commit -m 'my-new-feature > staging'
hg push

You then have your remote source control server push to all of your web servers using a trigger. A trigger on each web server will then do an update and reload the web server.

To move from staging to production, it's just as easy.

hg update production
hg merge staging
hg commit -m 'staging > production'
hg push

It's not the nicest method of deployment, and it makes rolling back quite hard. But it's quick and easy to set up, and still a lot better than manually deploying each change to each server.

I won't go through fabric, as it can get quite involved. You should read their documentation so you understand what it is capable of. There are plenty of tutorials around for fabric and django. I highly recommend the fabric route as it gives you lots more control, and only involves writing some python.

like image 145
Josh Smeaton Avatar answered Sep 18 '22 17:09

Josh Smeaton