2012/06/09

さくら VPS の Ubuntu Server 10.04 に git サーバーを構築

公開リポジトリは github でいいけれど、プライベートなリポジトリも欲しいよね。
というわけで、サーバーに git のリポジトリをたてるべく gitosis をさくらの VPS の Ubuntu Server 10.04 に導入したのでメモ。

# gitosis のインストール
pinzolo@server:~$ sudo aptitude install -y gitosis
[sudo] password for pinzolo: Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done The following NEW packages will be installed: gitosis python-pkg-resources{a} python-setuptools{a} 0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 318kB of archives. After unpacking 1,487kB will be used. Writing extended state information... Done Get:1 http://jp.archive.ubuntu.com/ubuntu/ lucid/main python-pkg-resources 0.6.10-4ubuntu1 [65.0kB] Get:2 http://jp.archive.ubuntu.com/ubuntu/ lucid/main python-setuptools 0.6.10-4ubuntu1 [213kB] Get:3 http://jp.archive.ubuntu.com/ubuntu/ lucid/universe gitosis 0.2+20090917-2 [40.4kB] Fetched 318kB in 0s (501kB/s) Preconfiguring packages ... Selecting previously deselected package python-pkg-resources. (Reading database ... 64406 files and directories currently installed.) Unpacking python-pkg-resources (from .../python-pkg-resources_0.6.10-4ubuntu1_all.deb) ... Selecting previously deselected package python-setuptools. Unpacking python-setuptools (from .../python-setuptools_0.6.10-4ubuntu1_all.deb) ... Selecting previously deselected package gitosis. Unpacking gitosis (from .../gitosis_0.2+20090917-2_all.deb) ... Setting up python-pkg-resources (0.6.10-4ubuntu1) ... Processing triggers for python-central ... Setting up python-setuptools (0.6.10-4ubuntu1) ... Processing triggers for python-central ... Setting up gitosis (0.2+20090917-2) ... Please read /usr/share/doc/gitosis/README.Debian for information about how to use gitosis. Processing triggers for python-support ... Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Done
# git ユーザーを作成 pinzolo@server:~$ sudo adduser git --system --shell /bin/sh --group --disabled-password --home /var/lib/git
Adding system user 'git' (UID 107) ... Adding new group 'git' (GID 116) ... Adding new user 'git' (UID 107) with group 'git' ... Creating home directory '/var/lib/git' ...
# gitosis 初期化 pinzolo@server:~$ sudo -H -u git gitosis-init < .ssh/id_rsa.pub
Initialized empty Git repository in /var/lib/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /var/lib/git/repositories/gitosis-admin.git/
# post-update フックスクリプトに実行権限を付与 pinzolo@server:~$ sudo chmod 755 /var/lib/git/repositories/gitosis-admin.git/hooks/post-update
これでサーバー上の作業はおしまい。

ここからローカルでの作業。

# 管理リポジトリを clone する
pinzolo@local % git clone git@server:gitosis-admin.git
Cloning into 'gitosis-admin'... remote: Counting objects: 5, done. remote: Compressing objects: 100% (5/5), done. remote: Total 5 (delta 0), reused 5 (delta 0) Receiving objects: 100% (5/5), done.
# リポジトリ内はこんな構造になっている pinzolo@local % cd gitosis-admin pinzolo@local % tree
. ├── gitosis.conf └── keydir └── pinzolo@mkt-sys.jp.pub 1 directory, 2 files
# gitosis.conf を編集 pinzolo@local % vim gitosis.conf
[gitosis] [group gitosis-admin] writable = gitosis-admin members = pinzolo@mkt-sys.jp # ここから追加 [group hoge] writable = hoge members = pinzolo@mkt-sys.jp
# 修正を commit して、反映させるために push(新しいリポジトリ hoge.git が作成される) pinzolo@local % git add gitosis.conf pinzolo@local % git status
# On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: gitosis.conf #
pinzolo@local % git commit -m "hogeリポジトリを追加"
[master 01e4aec] hogeリポジトリを追加 1 file changed, 4 insertions(+)
pinzolo@local % git push
Counting objects: 5, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 387 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To git@server:gitosis-admin.git 893246e..01e4aec master -> master
# サーバーのリポジトリを origin として登録し push する pinzolo@local % cd ~/projects/hoge pinzolo@local % git remote add origin git@server:hoge.git pinzolo@local % git push origin master
Counting objects: 5557, done. Delta compression using up to 2 threads. Compressing objects: 100% (5162/5162), done. Writing objects: 100% (5557/5557), 14.71 MiB | 145 KiB/s, done. Total 5557 (delta 1436), reused 0 (delta 0) To git@server:hoge.git * [new branch] master -> master

結構簡単に中央リポジトリのある開発ができますね。

さくら VPS (Ubuntu Server 10.04)設定エントリ一覧

0 件のコメント :

コメントを投稿