views:

1537

answers:

4

I have a site running on django, (but the question applies to anything, php, etc)

Currently I'm using unison to deploy my changes, and I (kinda used to) love it because before that I was doing it manually!!

Now, as I'm getting my feet wet with git, I'm starting to love it! And I'm thinking if maybe I should use it instead of unison to deploy my changes!

This way I'll have the added benefit of being able to revert my changes if somehow deploying them turned out to be a disaster!

The question is:

  • Is git suitable for deploying websites?

  • Any things/issues/gotchas that I should be aware of?

+3  A: 

Well, I use SVN to deploy my website, so I'd say go for it! Keep in mind that you may have to restart/reload the server every time you update the code for the website (I'm not sure if Django or whatever you're running it on is able to work around that).

David Zaslavsky
For reference: it's not directly django that governs whether the server needs to be reloaded, but the server-python bridge. In the Apache-w/-modpython configuration, changes to python code require a an apache restart, changes to templates (or static files) do not. ORM changes require much more.
David Berger
Technically mod_python's custom importer can reload changed Python code without a server restart, but I usually restart anyway to be safe.
David Zaslavsky
+8  A: 

If the question is if you can you use git to deploy your django application, the answer is sure!

However, production deployment of a popular application can become complex - and go way beyond just rolling back files. You may need to run DB scripts (both upgrade and downgrade scripts), restart cron jobs, or move files around.

As part of your deployment process you may want to back up your code base in its entirety so that you can rollback any number of versions back.

One way to do this is with Capistrano which automates the entire deployment process for you. You author scripts in your development environment and issue commands like: cap deploy, cap deploy_with_migrations, cap rollback, etc. and everything is automated from the login all the way up to the backup process and running DB scripts. By having the deployment automated you eliminate errors in your production environment. I recently spoke to an organization who accidentally deleted their entire database while in the midst of a deployment and needed to restore everything from backups. Deployment errors can really break your business so you want to automate this if you are serious about it.

Though Capistrano is a Ruby-based deployment tool commonly used with Rails, it's agnostic in terms of its automation capabilities. There are numerous posts on the Internet that discuss the benefits of deploying Django apps with Capistrano (google - django capistrano).

You can also check check out this link here

hyuan
I think you are over complicating this.. The question never mentions anything resembling popular/complex business websites.. but, capistrano is a good suggestion
dbr
+5  A: 

You can take a look at Fabric, popular among Djangonauts...

nabucosound
+9  A: 

I use git to track my website, and I deploy it like this:

git archive --format=tar --prefix="homepage/" master | gzip | ssh webserver "tar xvz -C ~/public_html"

This deserves a little explanation. The archive command for git will export the files for the master branch, which gets compressed with gzip to minimize network traffic. It's received remotely over ssh, which is decompressed into the final destination directory.

The deploy script that I use has a little more going on, but this is the most important piece.

Jeremy Cantrell
How do you arrange for files to be removed from the server? Can `rsync` take tar-style input?
mjs
With each deployment, a new, versioned, directory is created and symlinked to, which makes reverting easier. This is where the "has a little more going on" part comes into play.
Jeremy Cantrell