2013-12-28

gitの供用リポジトリの作り方

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
gitの共用リポジトリの作り方です。

用件としては、
・commitする人には認証をしてもらいたい
・でも認証なしでread onlyで使えるようにしたい
という感じのものです。

方法としては、commitはssh経由で行うようにしてread onlyはgitプロトコルでgit daemonで提供する感じになります。

環境はCentOS6です。

rootで実行します。

・git commitできるユーザが所属するgroupを追加
addgroup gitrepo

・commitできるユーザの登録
commitする人のアカウントを事前に作っておく必要があります。
そして上記のグループに追加します。
以下はユーザvivahirajにgit commitを許可する例です。
usermod -a -G gitrepo vivahiraj

・gitリポジトリ格納用ディレクトリを作成
mkdir /var/git

・公開用の認証なしでの利用ができるようにgitデーモンのインストール
yum -y install git-daemon

・gitデーモンの設定
vi /etc/xinetd.d/git
disableとserver_argsを変更します。
server_argsのほうでは、専用のリポジトリの指定したプロジェクトのみが公開されるようにするために--export-allと--user-pathをはずしました。
---------------------------------------------
#disable = yes
disable = no
#server_args = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
server_args = --base-path=/var/git --syslog --inetd --verbose
---------------------------------------------

・xinetdの自動起動設定と再起動
chkconfig xinetd on
service xinetd restart

以上で器はできました。



で個別プロジェクトのリポジトリの作成方法は以下のとおりです。
以下ではsampleというプロジェクトを作っているものとします。

・プロジェクト用の供用リポジトリの作成
cd /var/git
mkdir sample.git
cd sample.git
git --bare init --shared
cd ..
chgrp -R gitrepo sample.git
認証なしで公開する場合は以下も実行
touch sample.git/git-daemon-export-ok



で、実際にクライアント側からソースの初期登録を行う例です。
別途クライアント側から実行するものとします。 
初期データとしてsampleディレクトリに登録するものがある場合です。
リポジトリがあるサーバをgit.server.comとします。

・初期登録
cd sample
git init
git add .
git commit -m "first commit"
git remote add origin ssh://git.server.com/var/git/sample.git
git push origin master



ついでなので、リポジトリからソースを取得して変更するときの例です。

・取得と変更
git clone ssh://git.server.com/var/git/sample.git sample
cd sample
適当に変更
git add .
git commit -m "change test"
git push origin master

ちなみにgitプロトコルで公開設定したリポジトリにgemを登録しておけば、
bundler利用の場合だったら以下のように指定することでgemインストールすることができます。

gem 'sample', :git => 'git://git.server.com/sample.git'






0 件のコメント: