Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Are Experienced Web Developers Deploying Django Into Production on EC2?

I have never actually worked for a company which is deploying a Django App (with a large user base), and am curious about what is the best way to do this.

Right now I am hosting a Django App on EC2. The code for the app is sitting in my github account. I have nginx serving static content, and behind it a single apache server running django + mod_wsgi.

I am trying to figure out what the best practice is for "continuous deployment". Right now, after I have added additional functionality I do the following on EC2:

1) git reset HEAD --hard

2) git pull

3) restart apache

4) restart nginx

I have custom logic in my settings.py file so that if I am running on EC2, debug gets set to False, and my databases switch from sqlite3 (development) to mysql (production).

This seems to be working for me now, but I am wondering what is wrong with this process and how could I improve it.

Thanks

like image 543
josephmisiti Avatar asked Apr 14 '11 18:04

josephmisiti


4 Answers

I've worked with systems that use Fabric to deploy to multiple servers

like image 170
John Giotta Avatar answered Oct 25 '22 04:10

John Giotta


I'm the former lead developer at The Texas Tribune, which is 100% Django. We deployed to EC2 using RightScale. I didn't personally write the deployment scripts, but it allowed us to get new instances into the rotation very, very quickly and scales on-demand. it's not cheap, but was worth every penny in my opinion.

like image 30
Brandon Avatar answered Oct 25 '22 04:10

Brandon


I'd agree with John and say that Fabric is the tool to do this sort of thing comfortably. You probably don't want to configure git to automatically deploy with a post commit hook, but you might want to configure a fabric command to run your test suite locally, and then push to production if it passes.

Many people run separate dev and production settings files, rather than having custom logic in there to detect if it's in a production environment. You can inherit from a unified file, and then override the bits that are different between dev and production. Then you start the server using the production file, rather than relying on a single unified settings.py.

If you're just using apache to host the application, you might benefit from a lighter weight solution. Using fastcgi with nginx would allow you to do away with the overhead of apache entirely. There's also a wsgi module for nginx, but I don't know if it's production ready at this point.

like image 1
Paul McMillan Avatar answered Oct 25 '22 03:10

Paul McMillan


There is one more good way how to manage this. For ubuntu/debian amis it is good to manager versions and do deployemnts by packeging your application into .deb

like image 1
rootart Avatar answered Oct 25 '22 02:10

rootart