收录日期:2021/02/27 20:51:09 时间:2009-03-14 04:36:50 标签:django,git,deployment,project-management

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?

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.

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

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

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).