2010年5月5日 星期三

GIT Server 架設 (使用gitosis)

參考資料
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

http://ao2.it/wiki/How_to_setup_a_GIT_server_with_gitosis_and_gitweb

http://blog.agdunn.net/?p=277

以參考資料其實很容易就能把git server搞定.
這邊就只紀錄一下流程

< Server Side >

git clone git://eagain.net/gitosis.git

cd gitosis/

sudo apt-get install python-setuptools
sudo python setup.py install

sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git

請由 Local Side 產生KEY id_rsa.pub 並存放到 Server Side

ssh-keygen -t rsa

會在$HOME/.ssh/ 產生 id_rsa  id_rsa.pub

複製到Server Side /tmp

sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

< Local Side >

gitosis運用相當巧妙的方式管理git server.
gitosis 本身就是git server中的project.所以必須先從local side取出gitosis的副本.
透過編輯這個副本並上傳來管理所有的user & project.

git clone git@192.168.168.70:gitosis-admin.git

cd gitosis-admin

編輯gitosis.conf

增加一個新的Repository,格式如下

[group $REPOSITORY]
writable = $PROJECT
members = $USER

Commit new repository

git commit -a -m "New Repository"

git push

結果有Warning如下

warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 386 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.168.70:gitosis-admin.git
   1cfd916..4f2becf  master -> master

我找到的解決方式是

git config --add push.default current

到這邊基礎的設定已經完成,接著要實際將project同步到git server

首先到project source code目錄下

cd S3C6410

git init
git remote add origin git@192.168.168.70:s3c6410.git

將希望的目錄加入

git add android_kernel_smdk6410

git commit

實際將資料上傳

git push origin master:refs/heads/master

會看到以下的message

gigijoe@gigijoe-laptop:~/S3C6410$ git push origin master:refs/heads/master
Counting objects: 22134, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (21762/21762), done.
Writing objects: 100% (22134/22134), 233.26 MiB | 2374 KiB/s, done.
Total 22134 (delta 2456), reused 0 (delta 0)
To git@192.168.168.70:s3c6410.git
 * [new branch]      master -> master
gigijoe@gigijoe-laptop:~/S3C6410$

< Local Side >

新增user 的方式
進入gitosis-admin目錄中編輯
gitosis.conf.加入$USER1

[group $REPOSITORY]
writable = $PROJECT
members = $USER $OTHER_USER

接著由user產生key並將id_rsa.pub並重新命名擺放到
keydir/$USER1.pub

把檔案加入gitosis
git add keydir/$USER1.pub

更新並上傳
git commit
git push

之後就可以用 git clone 的方式取得 project

< Log >

gigijoe@gigijoe-laptop:~/gitosis-admin$ ls keydir/
gigijoe@gigijoe-desktop.pub  gigijoe@gigijoe-laptop.pub
gigijoe@gigijoe-laptop:~/gitosis-admin$ git add keydir/gigijoe@gigijoe-desktop.pub
gigijoe@gigijoe-laptop:~/gitosis-admin$ git commit
[master 82a65c0] Add gigijoe@gigijoe-desktop
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 keydir/gigijoe@gigijoe-desktop.pub
gigijoe@gigijoe-laptop:~/gitosis-admin$ git push
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 711 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@192.168.168.70:gitosis-admin.git
   d45919f..82a65c0  HEAD -> master



沒有留言:

張貼留言