2012年6月28日木曜日

「git-flowによるブランチ管理」を試してみる

git を使いこなすのが難しいと感じる今日このごろ。
皆様いかがお過ごしでしょうか。
gitを使っていると作業中のブランチどうするのとかいろいろ気になりますね。
でも、ブランチの管理って複雑なんだよなーとか・・・思っていたらオライリーのサイトで「git-flowによるブランチ管理」という目からうろこのような記事がありました。
ブランチ管理が共通化できて便利そうなので試してみること・・・。

ちなみにgit-daliyというGREEのインフラの方(sotarokさん)が作成したものもあるようです。
こちらは、PHPで作られているようですね。

参考

git-flow によるブランチの管理
A successful Git branching model(日本語訳)
gitflow

コマンドが出力するメッセージも合わせて記述しているので、多少見にくいかもしれません。
内容的にあまり変わりないと思うので、試したい場合は、上記参考サイトの「git-flowによるブランチ管理」をおすすめいたします。

試した環境

CentOS 6.2
Git version 1.7.11.1 (2012/6/28現在のリリースバージョン)

1. git-flowをインストールする

いきなり少し違いますが、この環境では、gitを/usr/local/gitにインストールしたので、コマンドにINSTALL_PREFIXオプションつけています。
sudo su -
cd /usr/local/src
wget --no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | env INSTALL_PREFIX=/usr/local/git/bin bash
chmod -R 755 /usr/local/git/bin

2. 空のリポジトリを作成する

git init --bare --shared=group foobar.git
cp foobar.git/hooks/post-update.sample foobar.git/hooks/post-update

3. 作業用のディレクトリに移動して空のリポジトリをcloneする

git clone /var/git/foobar.git

4. git-flowを導入する

cd foobar
git flow init
デフォルトのままEnterキーを押し続けます。
次の内容を聞かれますので必要があれば適宜で変更してください。
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
これなら既存のプロジェクトにも導入できますね。

5. 機能(helloworld)を追加する

git flow feature start helloworld
Switched to a new branch 'feature/helloworld'
Summary of actions:
- A new branch 'feature/helloworld' was created, based on 'develop'
- You are now on branch 'feature/helloworld'

Now, start committing on your feature. When done, use:

git flow feature finish helloworld

6. ブランチを確認する

git branch
develop
* feature/helloworld
master

7. 機能を追加する

vi helloworld.pl
#!/usr/bin/perl

use strict;
use warnings;

print "Hello World\n";

8. リポジトリに追加する

git add helloworld.pl
git commit -m "HelloWorld"

[feature/helloworld 0fabb48] HelloWorld
 1 file changed, 7 insertions(+)
 create mode 100755 helloworld.pl
コミットしました。

9. 開発用ブランチ(develop)にマージする

git flow feature finish helloworld

Switched to branch 'develop'
Updating e69c50f..0fabb48
Fast-forward
 helloworld.pl | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100755 helloworld.pl
 Deleted branch feature/helloworld (was 0fabb48).
 
 Summary of actions:
 - The feature branch 'feature/helloworld' was merged into 'develop'
 - Feature branch 'feature/helloworld' has been removed
 - You are now on branch 'develop'
上記のメッセージのとおり、
・feature/helloworldブランチがdevelopブランチにマージします。
・feature/helloworldブランチは削除されます。
・developブランチに切り替わります。

10. ブランチを確認する

git branch
* develop
  master
確かにそのとおりです。

11. developブランチをpushする

git push origin develop

Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 438 bytes, done.
Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
To /var/git/foobar.git
 * [new branch]      develop -> develop

12. ver1.0.0としてリリースブランチを作成する

git flow release start 1.0.0

Switched to a new branch 'release/1.0.0'
Summary of actions:
- A new branch 'release/1.0.0' was created, based on 'develop'
- You are now on branch 'release/1.0.0'

Follow-up actions:- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

  git flow release finish '1.0.0'

13. ブランチを確認

git branch
  develop
  master
  * release/1.0.0

14. READMEを作成する

vi README
README
====================================

- 1.0.0: print "Hello World"

14. リリースする

git add README
git commit -m 'update readme for release 1.0.0'

[release/1.0.0 e331ab0] update readme for release 1.0.0
 1 file changed, 4 insertions(+)
 create mode 100644 README
 
 git flow release finish 1.0.0
 
 # エディタが開きマージの内容やtagの入力など求められるので入力して保存する
 
 Switched to branch 'master'
 Merge made by the 'recursive' strategy.
 README        | 4 ++++
 helloworld.pl | 7 +++++++<
 2 files changed, 11 insertions(+)
 create mode 100644 README
 create mode 100755 helloworld.pl
 Switched to branch 'develop'
 Merge made by the 'recursive' strategy.
 README | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 README
 Deleted branch release/1.0.0 (was e331ab0).
 
 Summary of actions:
 - Latest objects have been fetched from 'origin'
 - Release branch has been merged into 'master'
 - The release was tagged '1.0.0'
 - Release branch has been back-merged into 'develop'
 - Release branch 'release/1.0.0' has been deleted

15. ブランチを確認する

git branch
* develop
master

16. タグを確認する

git tag
1.0.0

17. pushする

git push

Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 442 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
To /var/git/foobar.git
  0fabb48..e006137  develop -> develop

18. タグをpushする

git push origin 1.0.0

Counting objects: 2, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 342 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /var/git/foobar.git
* [new tag]         1.0.0 -> 1.0.0

19. 修正用のブランチを作成する

git flow hotfix start 1.0.1-bugfix

Switched to a new branch 'hotfix/1.0.1-bugfix'

Summary of actions:
- A new branch 'hotfix/1.0.1-bugfix' was created, based on 'master'
- You are now on branch 'hotfix/1.0.1-bugfix'

Follow-up actions:
- Bump the version number now!
- Start committing your hot fixes
- When done, run:

  git flow hotfix finish '1.0.1-bugfix'

20. ファイルを修正する

次のようにhelloworld.plに1行追加しました。
git diff
diff --git a/helloworld.pl b/helloworld.pl
index 2382e77..6fa1737 100755
--- a/helloworld.pl
+++ b/helloworld.pl
@@ -4,4 +4,5 @@ use strict;
 use warnings;
 
 print "Hello World\n";
 +print "BugFix\n";

21. 修正版をコミットする

git commit helloworld.pl -m "Bugfix."

[hotfix/1.0.1-bugfix be609ab] Bugfix.
 1 file changed, 1 insertion(+)

22. 修正版を適用する

git flow hotfix finish 1.0.1-bugfix

# マージする内容の確認やタグの入力など求められるので入力して保存する

Switched to branch 'master'
Merge made by the 'recursive' strategy.
 helloworld.pl | 1 +
 1 file changed, 1 insertion(+)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
 helloworld.pl | 1 +
 1 file changed, 1 insertion(+)
Deleted branch hotfix/1.0.1-bugfix (was be609ab).

Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch has been merged into 'master'
- The hotfix was tagged '1.0.1-bugfix'
- Hotfix branch has been back-merged into 'develop'
- Hotfix branch 'hotfix/1.0.1-bugfix' has been deleted

23. タグの確認

git tag
1.0.0
1.0.1-bugfix

24. pushする

git push

Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 501 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
To /var/git/foobar.git
   e006137..da2ab95  develop -> develop

git push origin 1.0.1-bugfix

Counting objects: 2, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 355 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /var/git/foobar.git
 * [new tag]         1.0.1-bugfix -> 1.0.1-bugfix
git flowすばらしいです。
私のようなブランチ管理が苦手な人でも使えそうです。

1点気になったのは、リリースのバージョン情報ですね。
細かい修正が多い場合は数値がどんどん追加されてカオスになりそうですね。
そのあたりの運用ポリシーをどうするかが問題になりそうです。

2012年6月19日火曜日

nginxでgitリポジトリの公開 - Smart HTTPを試してみた



nginxでgitリポジトリを公開してみます。
Smart HTTPというのが使えるようですが、こちらの例ではApache HTTP Serverでしたが、
特別なことは必要なさそうなので、nginxで試してみます。
80番ポートで通信できるとか、認証方法によっては鍵が必要なかったりといろいろ使い道がありそうですね。


こちらを参考にしました。



nginx 1.2.1を使用しますが、インストール手順は省略します。
上記の記事によるとgit-http-backendを動かす必要があるので、fcgiwrapを使ってみます。

fcgiwrapインストール




  • fcgiwrapインストール

yum -y install fcgi-devel.x86_64
cd /usr/loca/src
git clone git://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure --prefix=/usr/local/fcgiwrap
make
make install



  • fcgiwrapの起動

sudo -u www /usr/local/fcgiwrap/sbin/fcgiwrap -c2 -s unix:/tmp/fcgiwrap.sock >> /var/log/fcgiwrap.log &



nginx設定




  • 試しに設定したserverセクションです。

ドメイン名、パス、認証方法などは適宜変更してください。

server {
listen   80;
server_name git.example.com;

access_log /usr/local/nginx/logs/git/access_log;
error_log /usr/local/nginx/logs/git/error_log;

location / {
auth_basic            "Restricted";
auth_basic_user_file  htpasswd;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/git/libexec/git-core/git-http-backend;
fastcgi_param GIT_PROJECT_ROOT /var/git;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param PATH_INFO $uri;

fastcgi_pass unix:/tmp/fcgiwrap.sock;
}
}


設定が完了したらnginxを再起動します。
認証が無いと誰でもアクセスできるので、なんらかの認証は設定した方がいいですね。



gitリポジトリ作成




  • 空のリポジトリ作成と初期設定

git init --bare --shared=group foobar.git
cd foobar.git
cp hooks/post-update.sample hooks/post-update
git update-server-info
git config http.receivepack true



  • パーミッションの設定

環境の合わせて適宜gitリポジトリのディレクトリに設定してください。

動作確認



git clone http://git.example.com/foobar.git
Cloning into 'foobar'...
Username:
Password:
warning: You appear to have cloned an empty repository.

cd foobar
touch test.txt
git add .

git commit -m 'test'
[master (root-commit) b578ac5] test
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
git push origin master

git push origin master
Username:
Password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://git.example/com/foobar.git
* [new branch]      master -> master



pushができない(receivepackが有効でない場合のエラー)


receive-packの設定が無効の場合は、pushができませんでした。
アクセスログに401やWebDAVのPROPFINDメソッドとか出てたりしたので若干混乱します。
原因は、下記のようにfcgiwrapが出力するreceive-packの設定でした。

gitコマンドのエラー
error: Cannot access URL http://git.example.com/foobar.git/, return code 22
fatal: git-http-push failed

fcgiwrapのエラー
Service not enabled: 'receive-pack'


これらの必要な設定(http.receivepack)は、git-http-backend(1) Manual Pageに書いてありますね。

httpでも一通りgitが使えることが確認できました。




2012年6月7日木曜日

Pogoplug Series 4をアクティベートしてみた



さっそくPogoplug Serries 4 開封の儀


  • 本体、電源、LANケーブル、マニュアル

f:id:ono51:20120605080921j:image:w360


  • 背面には、右から電源、Ethernet、USB 3.0 x 2、謎のEJECTボタン

f:id:ono51:20120605080721j:image:w360


  • 上の蓋を開けるとSATAとUSB 2.0が見えます。

f:id:ono51:20120605080753j:image:w360
ちなみに開け方がわからなかったけど、ボタンとかロックとかなく手前から持ち上げるだけでした。
手前の白いボタンのようなものは、LEDが光るものでボタンではありません。


  • MacBookをSSDに換装したので余っていたHDD(2.5インチ)をとりあえずつないでみた。

f:id:ono51:20120605080819j:image:w360


  • LANケーブルと電源ケーブルをつないげてしばらくすると緑ランプが点灯します。

f:id:ono51:20120605081321j:image:w360
ちなみに固定IPアドレスは使えないようです。DHCPでIPアドレスを自動取得します。

ここからアクティベートの作業のためPCを使用します。


  • ブラウザで次のURLにアクセスします。


日本語の場合
http://my.pogoplug.com/ja/activate/
英語の場合
http://my.pogoplug.com/activate/



  • [次へ]をクリック

f:id:ono51:20120607010655j:image:w360


  • [次へ]をクリック

f:id:ono51:20120607013541j:image:w360


  • [次へ]をクリック

f:id:ono51:20120607013647j:image:w360


  • しばらく待ちます

f:id:ono51:20120607013648j:image:w360


  • [次へ]をクリック(今回は、2.5インチのHDDを接続済みなので)

f:id:ono51:20120607013649j:image:w360


  • メールアドレス、パスワードを入力して、「利用規約に同意します。」にチェックをつけ[送信]ボタンをクリック

f:id:ono51:20120607013650j:image:w360


  • pogoplug クラウドを奨められるが、とりあえず、無料5GBの[サインアップ]または[サインアップしない]をクリック

その他のプランは有料なので用途に合わせて選択してください。
f:id:ono51:20120607013651j:image:w360


  • Pogoplugの始め方について画面が表示されますので軽く読んで画面を閉じます。

f:id:ono51:20120607015528j:image:w360


  • これで完了ですが、日本語にしたい場合は、画面右下の[English]を[日本語]に変更してください。

f:id:ono51:20120607015526j:image:w360

少し困ったこと


アクティベートをやり直すために、管理画面から「Pogoplug で使用可能なデバイス」の「登録を取り消す」でデバイスを削除して何回かためしたところ、SATAのHDDがPogoplug上で認識しなくなりました。
ただ、その後、しばらく放置していると全面のLEDが黄色点滅となり、緑色点灯と変化して認識しました。
アクティベートをやり直した直後は前回認識したデバイスがすぐに認識しないようです。
しばらくすると自動で再認識するので慌てず放置しましょう。

以上です。




2012年6月6日水曜日

Pogoplug Series 4を購入してみた



前から気になっていたPogoplugですが、
いろいろ悩みましたが買ってしまいました。
f:id:ono51:20120605080627j:image:w320
悩んでいたと言ってもたいしたことないのですが、主に次の点です。


  • コスト

  • 大容量

  • 機能

  • ファイル共有

  • メンテナンス

まずコストの比較です。(2012/6/6現在)









サービス容量価格
Dropbox100GB約16000円/年
Google Drive100GB約4800円/年
Pogoplug Series 4-約9610円(本体のみ)
Pogoplug Mobile-約7980円(本体のみ)
平行輸入品なら約5900円(本体のみ)

Pogoplugですが、私の場合は、Pogoplug Series 4を購入したので若干高く9610円です。
あと、つなげるストレージですが、BuffaloのUSB 3.0 2TB HDDなら12000円ぐらいなので、
合計すると約22000円です。

ちなみに電気代も念のため確認してみました。
ワットチェッカーで計測したところ、2.5インチのHDDを接続してもアイドル時は6Wでした。
電気代にすごく詳しいわけではないのですが、1ヶ月100円程度ではないでしょうか。
私の使い方では、1日のうちアイドル時間がほとんどだと思うので多くても倍にはならないと思います。
Dropboxとの比較ではコストが1.5倍ですが、容量は20倍なので圧勝ですね。
使い方しだいですが、十分元がとれそうです。

ちなみにGoogle Driveが100GB/月と他と比べ安いですが、
月に1TB使うと、月額49.99ドルなので、約48000円/年と高くなります。

あと心配していた機能面ですが、アプリもiOS、Android対応していて特に問題ないですね。
保存するファイル数が多い場合は、つないだHDDを自分のPCに接続してファイルコピーとかもできます。
これで気兼ねなくガンガン上げられます。