2014-10-27 gitblit 入門
■gitblit 入門
gitblit とは
gitblit はオープンソースな git server。今は ticket も管理できるようになっている。
- 1.4.0 から ticketが追加。
- 1.5.0 から java7で動くようになった。
- 1.6.1 現在(そろそろ1.7.0がでそうだ)
gitblit を使うきっかけ
最初 gitlab(https://about.gitlab.com/) をつかっていたが遅い(gitのプロセス起動してパースしているので。https://gist.github.com/catatsuy/8827731 が詳しい)ので gitblit に乗り換えた。
gitblit はプラグインが groovy でかけるので気に入っている。
gitblit 自体は Java で Wicket をつかって書かれている。git 操作は JGit、検索には lucene を使っている。
いまなら gitbucket(https://github.com/takezoe/gitbucket) のほうがいいのかもしれないが、scala はよくわかんないのでカスタマイズしずらいので使っていない。gitbucket も jetty, jgit を使っているので java -jar gitbucket.war で起動する。検索は Solr かなとおもったが検索はまだ無いようだ。https://github.com/takezoe/gitbucket/issues/240
gitblit の導入
パターンとしては2つ。
WAR版:Tomcatなどのservletコンテナにwarをdeploy。
GO版:オールイン型(jetty組み込み)で解凍して gitblit.[cmd|sh] をうごかせば動くタイプ
基本GO版でいいと思う。
Windows版は http://dl.bintray.com/gitblit/releases/gitblit-1.6.1.zip
Linux版は http://dl.bintray.com/gitblit/releases/gitblit-1.6.1.tar.gz
Windows版をとってきて解凍するとディレクトリ構成は以下のようになっている。
>tree ├─amd64 ├─data │ ├─certs │ ├─git │ ├─gitignore │ ├─groovy ├─docs │ ├─bootstrap │ │ ├─css │ │ ├─img │ │ └─js │ ├─d3 │ └─prettify ├─ext ├─ia64 └─x86 >dir /B *.cmd add-indexed-branch.cmd authority.cmd gitblit-stop.cmd gitblit.cmd installService.cmd migrate-tickets.cmd reindex-tickets.cmd uninstallService.cmd >type gitblit.cmd @java -jar gitblit.jar --baseFolder data %* >type gitblit-stop.cmd @java -jar gitblit.jar --stop --baseFolder data %* >java -jar gitblit.jar --help ***************************************************************** Gitblit v1.6.1 ***************************************************************** --alias ALIAS : Alias of SSL certificate in keystore for serving https. --dailyLogFile : Log to a rolling daily log file INSTEAD of stdout. --gitPort PORT : Git Daemon port to serve. (port <= 0 will disable this connector) --help (-h) : Show this help --httpPort PORT : HTTP port for to serve. (port <= 0 will disable this connector) --httpsPort PORT : HTTPS port to serve. (port <= 0 will disable this connector) --ldapLdifFile FILE : Path to LDIF file. This will cause an in-memory LDAP server to be started according to gitblit settings --repositoriesFolder PATH : Git Repositories Folder --requireClientCertificates : Require client X509 certificates for https connections. --settings FILE : Path to alternative settings --shutdownPort PORT : Port for Shutdown Monitor to listen on. (port <= 0 will disable this monitor) --sshPort PORT : Git SSH port to serve. (port <= 0 will disable this connector) --stop : Stop Server --storePassword PASSWORD : Password for SSL (https) keystore. --tempFolder PATH : Folder for server to extract built-in webapp --userService VAL : Authentication and Authorization Service (filename or fully qualified classname) Example: java -server -Xmx1024M -jar gitblit.jar --repositoriesFolder c:\git --httpPort 80 --httpsPort 443
デフォルトで dataフォルダが基本ディレクトリになる(ここにプラグインとか証明書とかが入る)。
data/git がデフォルトの git repository になる。
gitbit のGO版の起動
>java -jar gitblit.jar 2014-10-25 10:27:38 [INFO ] ***************************************************************** 2014-10-25 10:27:38 [INFO ] _____ _ _ _ _ _ _ 2014-10-25 10:27:38 [INFO ] | __ \(_)| | | | | |(_)| | 2014-10-25 10:27:38 [INFO ] | | \/ _ | |_ | |__ | | _ | |_ 2014-10-25 10:27:38 [INFO ] | | __ | || __|| '_ \ | || || __| 2014-10-25 10:27:38 [INFO ] | |_\ \| || |_ | |_) || || || |_ 2014-10-25 10:27:38 [INFO ] \____/|_| \__||_.__/ |_||_| \__| 2014-10-25 10:27:38 [INFO ] Gitblit v1.6.1 2014-10-25 10:27:38 [INFO ] 2014-10-25 10:27:38 [INFO ] ***************************************************************** 2014-10-25 10:27:38 [INFO ] Running on Windows 8.1 (6.3) (略) 2014-10-25 10:27:48 [INFO ] jetty-9.2.3.v20140905 (略) 2014-10-25 10:28:17 [INFO ] Started @40714ms
jetty-9.2.3.v20140905 でうごいている。
最初は初期処理がはしるので時間がかかる。再起動すると Started @23528ms 半分ぐらい。
速いマシンだと Started @3047ms で立ち上がる。
gitbit へのアクセス
でアクセス可能になる。デフォルト https に対応していて(自己証明書だが)、httpではアクセスできない。
httpでアクセスする場合は data/gitblit.propertie の server.httpPort = 0 を変更するかコマンドラインオプションで --httpPort で指定が必要となる。
gitblit へのログイン
admin/adminではいれる
設定値はファイルなので
data/users.conf
にユーザを設定できる。
gitblit から clone
http://gitblit.com/setup_transport_http.html
httpsが自己証明書なのでhttps経由でgitをつかうなら
git clone --config http.sslVerify=false https://username@localhost:8843/hoge.git
のようにしないとエラーになるので注意。
gitblitをビルドする
http://gitblit.com/design.html
JDK 1.7 と Ant が必要。
>git clone https://github.com/gitblit/gitblit.git >cd gitblit >ant -p Main targets: buildApiLibrary Builds the Gitblit RPC client library buildFederationClient Builds the stand-alone Gitblit federation client buildGO Build Gitblit GO distribution buildManager Builds the stand-alone Gitblit Manager buildSite Build the Gitblit website buildWAR Build Gitblit WAR clean Cleanup all build artifacts and directories compile compiles Gitblit from source installMaven Install Gitblit JAR as Maven module installMoxie Install Gitblit JAR as a Moxie artifact nextMinorReleaseCycle prepare for the next minor release development cycle nextPointReleaseCycle prepare for the next point release development cycle publishBinaries Publish the Gitblit binaries to Bintray publishSite Publish the Gitblit site to a host report generate dependency report run Run Gitblit GO setup Setup up project tagRelease tag a new version and prepare for the next development cycle test compiles Gitblit from source and runs unit tests uploadMaven Upload Gitblit JAR to remote Maven repository Default target: compile >ant
ant では maven みたいに http://gitblit.github.io/moxie/ というantタスクをつかって jar をとってくるの(なので初回実行は待たされる)と
gitblit.properties から com.gitblit.Keys クラスが作成する。
あと src/main/distrib/data を data フォルダにコピーするなど実行に必要なことが行われる。
gitblit を ant で実行
>ant run
初回:Started @11334ms
2回目:Started @3905ms
早いな。java8でビルドしたからか?
gitblitを eclipse で実行
Eclipse などの ide(IDEAも対応している)にソースをimportしてビルド。特にEclipseプラグインを入れる必要もない。
あとは com.gitblit.GitBlitServer をJavaアプリケーションとして実行すればよい。
Started @7989ms で起動する。
なぜ同じマシンなのに ant、eclipse から実行だとGO版と起動時間ちがうのだ。
gitblit GO版だと起動に時間がかかっている遅い原因を調べる
>ant buildGO
で build/target に 配布物ができる。
展開して実行してみたが、 Started @16024ms となりやはり時間がかかっている。
log4j.properties に log4j.logger.org.eclipse.jetty=DEBUG を仕込んで確認してみた。
時間がかかっているのはここ
2014-10-25 13:09:58 [DEBUG] Extracting entry = null from jar file:/C:/oss/gitblit/build/target/gitblit-1.6.2-SNAPSHOT/gi tblit.jar 2014-10-25 13:10:07 [DEBUG] webapp=file:/C:/oss/gitblit/build/target/gitblit-1.6.2-SNAPSHOT/data/temp/webapp/
ようは gitblit.jar を解凍している部分がおそいということか。
7zip で解凍しても8秒ぐらいはかかっている。
ant or eclipseから実行だとすでに展開済みだからはやいのか。
java -jar gitblit.jar だと data/temp/webapp/ に展開して、終了時にフォルダを消している。
消さなくておいいと思ったがバージョンアップの時に困るか。。。
まあ、開発時ははやいので特にこまることはないが。。。。
gitblit でプラグイン開発
src/main/distrib/data/groovy にある *.groovy を参考にするとよい。
>dir /B src\main\distrib\data\groovy\*.groovy blockpush.groovy fisheye.groovy fogbugz.groovy jenkins.groovy localclone.groovy protect-refs.groovy redmine-fetch.groovy sendmail-html.groovy sendmail.groovy subgit.groovy thebuggenie.groovy
src/main/distrib/data/groovy のファイルを書き換えても data/groovy にコピーしないと反映されないので注意。
ちなみに ant setup でファイルで data/groovy にコピー可能。data/groovy を直接かえても ant setup はファイル日付をみているので上書きはされない。