Deploying on shared servers with git
November 23, 2011
This post was originally published in the Rambling Labs Blog on November 23, 2011.
There’s a project I’m currently working on, which is right now hosted on shared servers. I worked for a little while before on this project, but just to add some tiny features and fix some bugs, so I didn’t have the need back then to have a deployment process all set up.
But now, I’m probably going to be working for a couple of months on this, so I figured it would be better for my own sanity to just set everything up from the very beginning, to make the deployment process as easy as possible.
I googled for a while and the people seem to be using git for this. Now, there are a couple of options out there. There’s resmo’s git-ftp which is a git powered ftp client written as shell script, aizatto’s git-deploy which is also written as a shell script, and mislav’s git-deploy gem, which is written in ruby.
I was gonna try every one of them, but I decided to check the projects’ last commit date and pick the one that was most recently updated, which turned out to be the git-deploy gem. Also, it got my attention that the gem says
Heroku-style deployment in the project’s readme on GitHub.
It is easy to set up, as long as you have ssh and git in place both locally and on the server. I assure you that it will pay off almost immediately. Let’s set up ssh and git on the shared server first.
The first thing you need to do, is set up ssh for no more password prompts.
Then, you have to install git on your shared server, on which you probably have limited permissions. So, how do you do that? Well, you’ll have to download git from GitHub:
wget http://github.com/git/git/zipball/v184.108.40.206 -O ~/v220.127.116.11.zip
Extract it to the home directory:
cd ~ unzip v18.104.22.168 mv git-git-* git
And then compile it with:
cd ~/git make prefix=/usr all
After that, add this to the
~/.bashrc of your server:
if [ -d "$HOME/git/bin-wrappers" ]; then PATH="$PATH:$HOME/git/bin-wrappers" fi
When you’re finished with that, just proceed with the gem installation and setup. That is, installing the gem, adding the corresponding remote to your git repository (where your code will reside) and initializing git-deploy:
gem install git-deploy git add remote production firstname.lastname@example.org:/path/to/app git deploy setup -r production git deploy init
And that’s it! Now you can deploy with:
git push production master