Deploying with Git
Posted on 19/10/08 by Felix Geisendörfer
So we are using Git here at debuggable now. It takes all the pain out of deployment:
ssh <server> cd /var/www/<project> git pull
Not easy enough? Create a deploy.sh file:
ssh <server> "cd /var/www/<project> && git pull"
And once you get super lazy you'll find yourself doing:
git pull && git push && ./deploy.sh
Don't forget to get setup with ssh keys so, entering passwords all the time is a major PITA.
If you are just starting out with all this web craziness and still depend on ftp & shared hosting, try to get a VPS somewhere. I can recommend LiquidWeb (~$60 month). If there is anything I wish I had done 3 years earlier, it is to get a server with root access - it is so worth it.
How do you deploy these days?
-- Felix Geisendörfer aka the_undefined
You can skip to the end and add a comment.
www.slicehost.com is cheaper and you can select among more distros.
Forgot to mention Capistrano combined with Webistrano.
Falk: They look nice. I recommend LiquidWeb because they have rackspace kind of outstanding support. If you are new to managing a server, maintaining a LAMP stack can be quite intimidating : ).
Peritus: Python? I got a deploy script that has the config for all my projects and since I wrote it I have full flexibility. Not sure how fabric could help me : ).
I tend to deploy from SVN to a staging server (either on localhost or on a replica of the prod box) and then rsync from staging to prod.
It may seem OTT, but allows for a 'sanity check' before actually updating a production site.
are there any other VPS providers you can provide which are maybe a little bit cheaper?
Thanks in advance
Patrick: slicehost which was recommended by Falk looks solid and is a lot cheaper then liquid web. However, I can only personally recommend liquid web since we use them for a bunch of stuff, including hosting this blog (on one of their VPS machines).
Same deployoment procedure is possible with every other modern VCS, i. e. with Subversion, so no reason for hyping git ;)
Our deployment strategy for web apps: Staging from development environment to production is done via a Makefile action which does some configuration tasks for the production environment and all the cleanup stuff (emptying cache, etc.)
All deployment actions (and some more) are defined in a Makefile (google for 'GNU make'), so we simply do a 'make app', 'make complete', 'make dev2prod', 'make clear_cache', 'make show_error_log', 'make count_lines_of_code', or 'make generate_api_docs' ... you got it :)
In Makefiles you can define dependent actions, so a 'make dev2prod' requires a 'make disable_debug' before and does a 'make clear_cache' after, and so on ... Nice, isn't it?
I do the exact same thing - but with SVN. Dreamhost(my host) don't have git hosting yet(as far as I know).
I have an svn checkout on staging, then rsync to production.
@felix, could your deploy.sh script also run the schema update task, then delete all the model cache files too? How do you get it to work with different owners, are your app files owned by a particular user and your tmp files owned by apache?
hbl: I'm not hyping git. But if you have the option to use git and use SVN instead I might have to say a few not so nice things about svn ... I will look into makefile's so, just never needed them so far for something like deployment.
for us germans, i recommend teh vps services on hosteurope. they are starting by 13€/month
to the topic
deployment is not only to put some files to a location. it is a little bit more if someone will use it in a professional way. like complex builds. run automatic tests. and so on.
that's why i'm stick with a common svn-vcs in combination with a good build- and deployment-system like capistrano oder continuum.
Does git pull into a temporary directory first (.git) and then move the new contents in the real directory all at once, or does it update file by file? (like svn). Avoiding inconsistent code states is maybe not needed for small sites, but definitely needed for bigger sites.
Also, what happens when the new code brings along a database schema update? This is especially fun on bigger websites where alter table queries can take hours :-)
To decrease the PITA of setting up ssh keys, I did a script once that helps with installing them. It's called instkey.sh and can be found over at http://kvzlib.net
./instkey.sh hostname [username]
http://www.hostforweb.com have a good VPS package been using them for 5 years very reliable host. 1 VPS and 1 dedicated, they run their vps on quad core.
Dont expect too much from a vps they are still are shared hosting.
better get the cheap dedicated from server planet.
If you are looking for a very reliable root server I can really recommend www.hetzner.de . They are not cheap but offer very good support, have and have a fast and reliable connection.
However AFAIK the don't offer VPS'...
Dieter_be: It does a 'git fetch' first which downloads all new objects (blobs, commits, trees) into the .git/objects database. Then it merges the origin/master into the local master branch. Since you normally won't have local commits on your server, the merge will be a fast forward and essentially just a very quick file replace operation without anything being in an inconsistent state for longer then a ms (if that).
For a site that is still under development I sometimes just have a script that dumps my local db, scp's it up the staging server and then overwrites the old db ; ). For bigger sites you'll have to keep track of all local db changes (we use a trac ticket + comments) and then run them on the server. If your queries take hours and would slow your site down, you'll need a master / slave setup and could keep the slaves responsive during the update. But sometimes you might need to announce some downtime ...
for some php developers, they are still having a hard time to understand Git. Maybe there were already used to SVN.
Joe Siao: I'm working on something to fix that. Check for a post on it here soonish : ).
So far, I am still using fredistrano for all my web developments (intranet + dreamhost). For those who never heard about it, its a web application that automates the deployment process from a subversion repository to your production server (quite similar to webistrano).
NB: Actually, we have just released a new version with many new features. you might give it a try at http://code.google.com/p/fredistrano/.
it would be great if you wrote a post on what you didn't like in svn and how git helped you resolve those problems.
thx, regards, dan
We are moving to git away from svn. There is not much difference in terms of deployment if you have a good deployment process.
I recommend ServerGrove - http://servergrove.com/vps Great PHP support at good prices. Check it out.
I use Capistrano to deploy all my apps because of the following
* doesn't care what version control system you use as it supports all the biggies
* doesn't care what type of app you are deploying
* allows you to not only deploy, but roll back
* very scriptable with their deployment scripts with an incredibly minimal investment in Ruby
I would recommend Media Temple - mediatemple.net. I have used their services for over 6 years including the (DV)dedicated virtual and the (GS)grid server with zero issues. When I need something, they are on top of it very quickly. I really can't say enough good things about them.
Regarding Git or SVN, I haven't used Git but within the hour I saw a discussion of Git on Slashdot:
.... and a short scenario comparison here:
Using fredistrano here too, great tool.
BTW - now Slicehost has been acquired by Rackspace I'd say they are hands-down the best option for a VPS now.
This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.
We deploy using fabric(see nongnu.org slash fab) which is a thin layer over ssh doing what you attempt to do with shell-scripts. With multi-host support!