Deploying Rails to Centos 5
- Part 1 // Apache
- Part 2 // mySQL
- Part 3 // Git
- Part 4 // Ruby, Gems & Rails
- Part 5 // Passenger
- You are here!
- Part 7 // Capistrano
You should have Apache, mySQL, rails and Passenger installed by now. And of course, you will need to have Git installed as well. You could actually install Gitosis in another remote server but for me, Gitosis resides in the same remote server that I have been working in. To get Gitosis to work, you need to install Python as Gitosis is written in it.
yum install python-setuptools
When you are done, get out to the root of your server and clone gitosis
git clone git://eagain.net/gitosis.git
Now go into the directory and run the installer.
cd gitostis python setup.py install
When gitosis is installed you can safely delete the gitosis folder by running
rm -rf gitosis
Now you need to set up a shell user to access Gitosis.
adduser --shell /bin/sh --group --disabled-password --home /home/git git
When you are done, you should have a
/home/git folder ready for your repositories to reside in.
You already know that to git clone or push you have to roughly do a
git clone firstname.lastname@example.org:reponame.git
To have this setup you need to provide Gitosis your SSH key from your local computer.
So in your local computer’s terminal.
local $ ssh-keygen -t rsa
However, if you already have an
id_rsa.pub generated before you can actually skip this step and use your existing one instead.
Either way, once you have an
id_rsa.pub file in your
~/.ssh folder run this command to copy it to your remote server
local $ scp $HOME/.ssh/id_rsa.pub email@example.com:/home/git
If you run into an error you can manually copy the text in
id_rsa.pub file and make the exact same file in
remote $ vim id_rsa.pub
Paste in the text you copied from your local file.
Once you are done, you are ready to initialize Gitosis.
remote $ su git remote $ -H -u git gitosis-init < id_rsa.pub
It should initialize and reinitialize a git repo. Now you can remove the
id_rsa.pub in your remote computer.
Now do some permissions changing.
remote $ chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update chmod 755 /home/git chmod 700 /home/git/.ssh chmod 644 /home/git/.ssh/authorized_keys
Back to your local computer’s terminal, head to an empty folder and clone the
local $ git clone firstname.lastname@example.org:gitosis-admin.git
If you couldn’t get past cuz of ssh or there is no git repo in that location. You need to change your local computer’s ssh config file.
Mine was in
/private/etc/ssh_config. You can google to find the location of your ssh config file in your OS. Add this two lines in to make it automagically work
Host yourdomain.com Port 1234
Replay with your remote server’s ServerName.com and the SSH port.
When you are able to clone, head into the local
gitosis-admin directory either through terminal or by navigating there in Finder. Open up
gitosis.conf and add the following lines:
[group reponame] writable = reponame members = copy-from-gitosis-admin-chunk-above
Back to your local terminal, you can now do some cool things to push the changes you did back to your remote server. Hehe.
local $ git commit -a -m "Allow my local have write access to remote" git push
Now if you check your remote server’s
gitosis.conf file you will be pleased to see that it is updated.
The last thing to do here is to initialize a git setup in your local development app.
git init git remote add origin email@example.com:reponame.git git add . # add whole project git commit -m "Initial code for myblog" git push origin master:refs/heads/master
With this you will have your latest branch of your development app pushed to your very own Gitosis server, ready to deploy with Capistrano.
Note : If you want to be able to push from your remote app back to your Gitosis, you can generate the
id_rsa.pub key from your remote server and place the file in the
gitosis-admin/keydir directory. Update your
gitosis.conf and you should have access to the project.
Next : Capistrano