0

Question 1:

I am about to deploy my first Django website and I was wondering what tools are recommended to gathering all your Django files.

Like for example I don't need my sass and coffeescript files I just want the compiled css and js files. I also want to use the correct production settings file.

Question 2:

Do I put these files ready for deployment into their own version control repository? I guess the advantage is that you can easily roll back changes?

Question 3:

Do I run my tests before gathering the files or before deploying?

Shell scripts could be a solution but maybe there is a better way? I looked at jenkins/hudson but that seems more like a tool that sits on top of the tools that I am looking for.

Pickels
  • 33,902
  • 26
  • 118
  • 178

2 Answers2

2

For questions one and two, I'd recommend using a version control system for this. I'm sure you're already using some sort of version control, so you can just say which branch of your repository you would like to deploy. And yes, this makes rollbacks incredibly easy. Probably the most popular method for Django deployment is to package your files using git, and then deploy these files and run any deployment scripts using fabric.

Using git, packaging your files using your local repository would look something like:

git archive --format=tar HEAD | gzip > my_repo.tar.gz

Alternately, you can first push your changes to a github repository, and then in your deployment script just clone your repository from your production server.

For your third question, if you use this version control method for packaging your files, then just make sure when you are testing you have the deployment branch checked out.

Spike
  • 5,040
  • 5
  • 32
  • 47
  • Well deployment it self is no problem. I got a beta invite to dotcould so I just have to push my project using their api. Was just wondering how to get a clean project that I can push. Without the source files and local settings files etc. – Pickels Mar 27 '11 at 22:20
  • It's a good idea to have a "clean" version of your project living under a branch of your version control repository. You can easily specify what files you want in it and what files you don't. Then you can just package that branch up by using 'git archive' and push your project. If you're worried about .pyc files or things like that making your project look messy, you can set your repository to ignore those in .gitignore so none of those types of files will make it into the repo. – Spike Mar 28 '11 at 04:20
  • Here is some more information on deployment branches: http://stackoverflow.com/questions/487753/how-to-realise-a-deployment-branch-in-git – Pickels Mar 28 '11 at 10:50
1

I'll typically use Fabric for deploying most Django projects:

http://docs.fabfile.org/en/1.0.0/?redir

It has a decent api for communicating with remote servers and it's all in Python – bonus!

You don't need to store your concatenated media files in a separate repo. They're only needed for production. In that case I've found libraries like django-mediasync and django-compress to be useful. They both provide template tags/settings that can concatenate and cache your static files for you depending on the DEBUG setting/environments (production vs development).

You can run your tests whenever. Some people will run them as a version control hook to prevent broken code from being checked in or during deployment, stopping the deployment in case of test failure.

Derek Reynolds
  • 3,473
  • 3
  • 25
  • 34