m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

gitoliteで管理しているリポジトリをgitwebでWebで参照

力技なんで参考にはならんけど

まあ、あって損はない感じなので記載

とりあえず、gitのソースコードを取得
[root@localhost ~]# cd /home/git/
[root@localhost git]# mkdir tmp
[root@localhost git]# cd tmp/
[root@localhost tmp]# git clone https://github.com/git/git.git git
Cloning into 'git'...
remote: Counting objects: 168311, done.
remote: Compressing objects: 100% (45967/45967), done.
remote: Total 168311 (delta 121069), reused 167327 (delta 120355)
Receiving objects: 100% (168311/168311), 57.19 MiB | 1.52 MiB/s, done.
Resolving deltas: 100% (121069/121069), done.
Checking connectivity... done.
Checking out files: 100% (2635/2635), done.
[root@localhost tmp]#

INSTALLとか読んでmakeとかしてみたけどなんかわからなかった。orz
とりあえず、makeをかます

[root@localhost tmp]# cd git/gitweb/
[root@localhost gitweb]# ll
合計 284
-rw-r--r-- 1 root root  14728  2月 28 06:39 2014 INSTALL
-rw-r--r-- 1 root root   5641  2月 28 06:39 2014 Makefile
-rw-r--r-- 1 root root   2392  2月 28 06:39 2014 README
-rwxr-xr-x 1 root root 251558  2月 28 06:39 2014 gitweb.perl
drwxr-xr-x 3 root root   4096  2月 28 06:39 2014 static
[root@localhost gitweb]#
gitweb.perlがあるけど多分、「gitweb.cgi」に名前変更すればいいのかも?

なんかいろいろmakeしてたらいつの間にかできてた。

[root@dti-vps-srv67 gitweb]# make
    SUBDIR ../
GIT_VERSION = 1.9.0
make[1]: `GIT-VERSION-FILE' は更新済みです
    SUBDIR ../
make[1]: `GIT-VERSION-FILE' は更新済みです
    GEN gitweb.cgi
    GEN static/gitweb.js
[root@localhost gitweb]# ll
合計 540
-rw-r--r-- 1 root root    842  2月 28 06:40 2014 GITWEB-BUILD-OPTIONS
-rw-r--r-- 1 root root  14728  2月 28 06:39 2014 INSTALL
-rw-r--r-- 1 root root   5641  2月 28 06:39 2014 Makefile
-rw-r--r-- 1 root root   2392  2月 28 06:39 2014 README
-rwxr-xr-x 1 root root 251308  2月 28 06:40 2014 gitweb.cgi
-rwxr-xr-x 1 root root 251558  2月 28 06:39 2014 gitweb.perl
drwxr-xr-x 3 root root   4096  2月 28 06:40 2014 static
[root@localhost gitweb]#
git配下に「gitweb」ディレクトリがあるのでコピー
gitweb
  - gitweb.cgi
  - gitweb.psgi
  - gitweb
    -  static 

※(1)/home/git配下に「gitweb」を作成
※(2)「gitweb.perl」または「gitweb.cgi」を/home/git/gitwebへコピー
※(3)さらに「gitweb」を作成して「static」をディレクトリ毎コピー

gitweb.psgiを作成
#!/usr/env/perl

use Plack::App::WrapCGI;
use Plack::Builder;

my $app =
  Plack::App::WrapCGI->new( script => '/home/git/gitweb/gitweb.cgi' )
  ->to_app;
builder {
    enable "Plack::Middleware::Static",
      path => qr{^/gitweb/static/},
      root => '.';
    $app;
};
さらにgitweb.cgiを力技で変更
72行目あたり

# core git executable to use
# this can just be "git" if your webserver has a sensible PATH
# our $GIT = "/usr/local/bin/git";
our $GIT = "/usr//bin/git";

# absolute fs-path which will be prepended to the project path
#our $projectroot = "/pub/scm";
# our $projectroot = "/home/local/scm";
our $projectroot = "/home/git/repositories";

# fs traversing limit for getting project list
# the number is relative to the projectroot
our $project_maxdepth = 2007;

# string of the home link on top of all pages
our $home_link_str = "projects";
実行
[root@localhost gitweb]# plackup gitweb.psgi
HTTP::Server::PSGI: Accepting connections at http://0:5000/

※失敗する場合はモジュールが不足していることになるらしいのでインストールを行う

画面

f:id:m_shige1979:20140227005349j:plain

まとめ

参照するだけならコレで行けそう。ただ、常時自動したままにするか、一時的に起動するかで対応するのが悩みどころ。
VPSなどで公開することになったりしたらセキュリティの防御としてベーシック認証あたりは必要なんで。
Webサーバとして監視したい場合はStarman+Nginxとかで連携する。