{"id":1637,"date":"2011-05-03T11:22:19","date_gmt":"2011-05-03T03:22:19","guid":{"rendered":"http:\/\/hazelong.com\/?p=1637"},"modified":"2011-05-04T16:54:35","modified_gmt":"2011-05-04T08:54:35","slug":"deploying-rails-centos-5-gitosis","status":"publish","type":"post","link":"https:\/\/musenmaker.com\/hazelong\/?p=1637","title":{"rendered":"Deploying Rails to Centos 5 : Gitosis"},"content":{"rendered":"<p>Why use <a href=\"http:\/\/github.com\">GitHub<\/a> when you can have your own? Hehe. <a href=\"http:\/\/eagain.net\/gitweb\/?p=gitosis.git;a=summary\">Gitosis<\/a> is a nice way of having your very own private repository. And it&#8217;s free! It just takes a while to set it up.<\/p>\n<p><strong>Deploying Rails to Centos 5<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/hazelong.com\/?p=1618\"><strong>Part 1 \/\/ Apache<\/strong><\/a><\/li>\n<li><a href=\"http:\/\/hazelong.com\/?p=1622\"><strong>Part 2 \/\/ mySQL<\/strong><\/a><\/li>\n<li><a href=\"http:\/\/hazelong.com\/?p=1625\"><strong>Part 3 \/\/ Git<\/strong><\/a><\/li>\n<li><a href=\"http:\/\/hazelong.com\/?p=1631\"><strong>Part 4 \/\/ Ruby, Gems &amp; Rails<\/strong><\/a><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1634\">Part 5 \/\/ Passenger<\/a><\/strong><\/li>\n<li><strong>You are here!<\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/blog\/2011\/05\/04\/deploying-rails-centos-capistrano\/\">Part 7 \/\/ Capistrano<\/a><\/strong><\/li>\n<\/ul>\n<p>You should have <a href=\"http:\/\/hazelong.com\/?p=1618\">Apache<\/a>, <a href=\"http:\/\/hazelong.com\/?p=1618\">mySQL<\/a>, <a href=\"http:\/\/hazelong.com\/?p=1631\">rails<\/a> and\u00a0<a href=\"http:\/\/hazelong.com\/?p=1634\">Passenger<\/a> installed by now. And of course, you will need to have <a href=\"http:\/\/hazelong.com\/?p=1625\">Git<\/a> 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. [shell] yum install python-setuptools[\/shell]<\/p>\n<p>When you are done, get out to the root of your server and clone gitosis [shell]git clone git:\/\/eagain.net\/gitosis.git[\/shell]<br \/>\nNow go into the directory and run the installer. [shell]cd gitostis<br \/>\npython setup.py install[\/shell]<\/p>\n<p>When gitosis is installed you can safely delete the gitosis folder by running[shell] rm -rf gitosis[\/shell]<\/p>\n<p>Now you need to set up a shell user to access Gitosis. [shell]adduser &#8211;shell \/bin\/sh \\<br \/>\n&#8211;group \\<br \/>\n&#8211;disabled-password \\<br \/>\n&#8211;home \/home\/git \\<br \/>\ngit[\/shell]<br \/>\nWhen you are done, you should have a <code>\/home\/git<\/code> folder ready for your repositories to reside in.<\/p>\n<p>You already know that to git clone or push you have to roughly do a [shell]git clone git@yourdomain.com:reponame.git[\/shell]To have this setup you need to provide Gitosis your SSH key from your local computer.<\/p>\n<p>So in your local computer&#8217;s terminal.[shell] local $ ssh-keygen -t rsa[\/shell] However, if you already have an <code>id_rsa.pub<\/code> generated before you can actually skip this step and use your existing one instead.<\/p>\n<p>Either way, once you have an <code>id_rsa.pub<\/code> file in your <code>~\/.ssh<\/code> folder run this command to copy it to your remote server[shell]local $ scp $HOME\/.ssh\/id_rsa.pub user@111.111.111.111:\/home\/git[\/shell]<\/p>\n<p>If you run into an error you can manually copy the text in <code>id_rsa.pub<\/code> file and make the exact same file in <code>\/home\/git<\/code> by [shell]remote $ vim id_rsa.pub[\/shell] Paste in the text you copied from your local file.<\/p>\n<p>Once you are done, you are ready to initialize Gitosis. [shell]remote $ su git<br \/>\nremote $ -H -u git gitosis-init &lt; id_rsa.pub [\/shell] It should initialize and reinitialize a git repo. Now you can remove the <code>id_rsa.pub<\/code> in your remote computer.<\/p>\n<p>Now do some permissions changing.[shell]remote $<br \/>\nchmod 755 \/home\/git\/repositories\/gitosis-admin.git\/hooks\/post-update<br \/>\nchmod 755 \/home\/git<br \/>\nchmod 700 \/home\/git\/.ssh<br \/>\nchmod 644 \/home\/git\/.ssh\/authorized_keys<br \/>\n[\/shell]<\/p>\n<p>Back to your local computer&#8217;s terminal, head to an empty folder and clone the <code>gitosis-admin<\/code> files. [shell] local $ git clone git@yourdomain.com:gitosis-admin.git[\/shell]<br \/>\nIf you couldn&#8217;t get past cuz of ssh or there is no git repo in that location. You need to change your local computer&#8217;s ssh config file.<br \/>\nMine was in <code>\/private\/etc\/ssh_config<\/code>. 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 [shell]Host yourdomain.com<br \/>\nPort 1234[\/shell]<br \/>\nReplay with your remote server&#8217;s ServerName.com and the SSH port.<\/p>\n<p>When you are able to clone, head into the local <code>gitosis-admin<\/code> directory either through terminal or by navigating there in Finder. Open up <code>gitosis.conf<\/code> and add the following lines:<br \/>\n[shell][group reponame]<br \/>\nwritable = reponame<br \/>\nmembers = copy-from-gitosis-admin-chunk-above[\/shell]<\/p>\n<p>Back to your local terminal, you can now do some cool things to push the changes you did back to your remote server. Hehe.[shell]local $ git commit -a -m &#8220;Allow my local have write access to remote&#8221;<br \/>\ngit push[\/shell]<\/p>\n<p>Now if you check your remote server&#8217;s <code>gitosis.conf<\/code> file you will be pleased to see that it is updated. \ud83d\ude42<\/p>\n<p>The last thing to do here is to initialize a git setup in your local development app. [shell]git init<br \/>\ngit remote add origin git@yourdomain.com:reponame.git<br \/>\ngit add . # add whole project<br \/>\ngit commit -m &#8220;Initial code for myblog&#8221;<br \/>\ngit push origin master:refs\/heads\/master[\/shell]<br \/>\nWith this you will have your latest branch of your development app pushed to your very own Gitosis server, ready to deploy with Capistrano.<\/p>\n<p><em><strong>Note <\/strong>: If you want to be able to push from your <strong>remote<\/strong> app back to your Gitosis, you can generate the <code>id_rsa.pub<\/code> key from your remote server and place the file in the <code>gitosis-admin\/keydir<\/code> directory. Update your <code>gitosis.conf<\/code> and you should have access to the project.<\/em><\/p>\n<p><strong>Next : Capistrano<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why use GitHub when you can have your own? Hehe. Gitosis is a nice way of having your very own private repository. And it&#8217;s free! It just takes a while to set it up. Deploying Rails to Centos&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1776],"tags":[1845,1836,1841,1844,1843,1788,1842],"class_list":["post-1637","post","type-post","status-publish","format-standard","hentry","category-coding-tutorials","tag-capistrano","tag-centos","tag-git","tag-gitosis","tag-passenger","tag-rails","tag-ruby"],"acf":[],"_links":{"self":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts\/1637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1637"}],"version-history":[{"count":0,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts\/1637\/revisions"}],"wp:attachment":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}