ひよっこ。

I want to…

Archive for 2012年9月

phabricatorをインストールしてみた

Posted by hikaruworld : 2012 9月 15

コードレビューツール 6選 どれが最適?で紹介されていたphabricatorに素敵さを感じました。
Ubuntuだとインストールスクリプトが準備されているということで、さくっと?インストールしてみました。

基本的な流れは、こんな感じになりました。
1. ソースの取得と展開
2. 各種設定ファイルの定義
3. セットアップウィザードの実行
4. ログインアカウントの作成

構築した環境は、 lsb_release -aで確認すると以下の通り

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.1 LTS
Release: 12.04
Codename: precise

インストールしたphabricatorのhashはeaf7aedb05d01ffab4cceb1bf52cfa084c74d489でした。

なお、virtualbox上に構築されてるUbuntuなので該当のIPアドレスを192.168.56.101とします。

1.アプリケーションの取得とインストール

詳しくはこちらInstallation_Guideを参照しましょう。
今回は/opt/phabricator以下にインストールします。

sudo mkdir /opt/phabricator
sudo chown -R morizou:morizou phabricator/
cd /opt/phabricator
wget http://www.phabricator.com/rsrc/install/install_ubuntu.sh
chmod +x install_ubuntu.sh
./install_ubuntu.sh

以下の様に標準出力にメッセージが流れます。

PHABRICATOR UBUNTU INSTALL SCRIPT
This script will install Phabricator and all of its core dependencies.
Run it from the directory you want to install into.

Phabricator will be installed to: /opt/phabricator.
Press RETURN to continue, or ^C to cancel.

と確認されるのでEnterで。

Testing sudo…
Installing dependencies: git, apache, mysql, php…

パッケージリストを読み込んでいます… 完了

…省略…

35.8 MB のアーカイブを取得する必要があります。
この操作後に追加で 119 MB のディスク容量が消費されます。
続行しますか [Y/n]?

と聞かれるので当然YESで。apt-getとgit cloneで必要な依存モジュールがインストールされます。

取得:1 http://jp.archive.ubuntu.com/ubuntu/ precise/main apache2-mpm-prefork i386 2.2.22-1ubuntu1 [2,400 B]
取得:2 http://jp.archive.ubuntu.com/ubuntu/ precise/main libnet-daemon-perl all 0.48-1 [43.1 kB]

….省略…

Cloning into ‘libphutil’…
remote: Counting objects: 4717, done.
remote: Compressing objects: 100% (1821/1821), done.
remote: Total 4717 (delta 2887), reused 4575 (delta 2752)
Receiving objects: 100% (4717/4717), 1.12 MiB | 169 KiB/s, done.
Resolving deltas: 100% (2887/2887), done.
Cloning into ‘arcanist’…
remote: Counting objects: 6512, done.
remote: Compressing objects: 100% (2644/2644), done.
remote: Total 6512 (delta 4015), reused 6254 (delta 3763)
Receiving objects: 100% (6512/6512), 1.18 MiB | 212 KiB/s, done.
Resolving deltas: 100% (4015/4015), done.
Cloning into ‘phabricator’…
remote: Counting objects: 46594, done.
remote: Compressing objects: 100% (17230/17230), done.
remote: Total 46594 (delta 29339), reused 45607 (delta 28464)
Receiving objects: 100% (46594/46594), 8.07 MiB | 744 KiB/s, done.
Resolving deltas: 100% (29339/29339), done.
Submodule ‘externals/javelin’ (git://github.com/facebook/javelin.git) registered for path ‘externals/javelin’
Cloning into ‘externals/javelin’…
remote: Counting objects: 1814, done.
remote: Compressing objects: 100% (669/669), done.
remote: Total 1814 (delta 1131), reused 1782 (delta 1104)
Receiving objects: 100% (1814/1814), 546.50 KiB | 207 KiB/s, done.
Resolving deltas: 100% (1131/1131), done.
Submodule path ‘externals/javelin’: checked out ‘6ad17a59326690ed11c4b72c506a6218e438cad9’

Install probably worked mostly correctly. Continue with the ‘Configuration Guide’:

http://www.phabricator.com/docs/phabricator/article/Configuration_Guide.html

You can delete any php5-* stuff that’s left over in this directory if you want.

問題なくインストールされると上記の様にログが出力されます。
ちなみにディレクトリ的にはこんな感じになりました。

/opt/phabricator
├── arcanist
├── install_ubuntu.sh
├── libphutil
└── phabricator

注意事項:Proxyが原因でgit cloneに失敗する場合

通常プロキシ環境においてgit clone https://…が通っていても、host名が解決出来ずエラーになってしまいました。
スクリプト自体が、git://プロトコルで定義されている事、
https_proxyの環境設定が伝わらなかった事が原因だったので、
以下のようにスクリプトを修正しました

7a8,10
> export https_proxy=http://proxy.com:80
>
>
62c65
<   git clone git://github.com/facebook/libphutil.git
---
>   git clone https://github.com/facebook/libphutil.git
69c72
<   git clone git://github.com/facebook/arcanist.git
---
>   git clone https://github.com/facebook/arcanist.git
76c79
<   git clone git://github.com/facebook/phabricator.git
---
>   git clone https://github.com/facebook/phabricator.git
79a83,85
>
> sudo sed -i s/git:/https:/g phabricator/.gitmodules
> sudo sed -i s/git:/https:/g phabricator/.git/config

2.アプリケーションの設定

無事インストール?が終わったら、設定を行っていきます。
ここからの説明はConfiguration_Guideに書かれているのでその手順に従います。

2.1設定ファイルを作成

myconfig.conf.phpというファイルを新規に作成します。

mkdir -p /opt/phabricator/phabricator/conf/custom/
cd /opt/phabricator/phabricator/conf/custom/
touch myconfig.conf.php

ファイル設定に関しては設定ガイドのサンプルを修正します。
phabricator.base-urimysql.*関連の修正と、
メールを送信しない場合はmetamta.mail-adapterを新規に定義します。
というか、metamta.mail-adapterの設定しないとセットアップ中に失敗しますのでご注意を(詳細は下記参照)。

こんな感じに設定しています。

<?php

return array(

  // Important! This will put Phabricator into setup mode to help you
  // configure things.
  'phabricator.setup' => true,

  // This will be the base domain for your install, and must be configured.
  // Use "https://" if you have SSL. See below for some notes.
  'phabricator.base-uri' => 'http://192.168.56.101',

  // Connection information for MySQL.
  'mysql.host' => 'localhost',
  'mysql.user' => 'root',
  'mysql.pass' => 'mysqlrootpassword',

  // Basic email domain configuration.
  'metamta.default-address' => 'noreply@phabricator.example.com',
  'metamta.domain'          => 'phabricator.example.com',
  'metamta.mail-adapter'    => 'PhabricatorMailImplementationTestAdapter'

  // NOTE: Check default.conf.php for detailed explanations of all the
  // configuration options, including these.

) + phabricator_read_config_file('production');
?>

2.2. 環境変数の設定

PHABRICATOR_ENVの環境変数を設定が必要なので、.bashrcPHABRICATOR_ENV=custom/myconfigを追記しておきます。

echo "export PHABRICATOR_ENV=custom/myconfig" >> ~/.bashrc
source ~/.bashrc

2.3. Apache2の設定

PHPさんなので、apache2で起動設定を行います。
設定ガイドではVirtualHostで設定していますが、面倒なのでdefault(http://192.168.56.101/)で動くようにします。
/etc/apache2/sites-available/defaultを以下のように修正します。

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        ServerName localhost.com

        #DocumentRoot /var/www
        DocumentRoot /opt/phabricator/phabricator/webroot

        RewriteEngine on
        RewriteRule ^/rsrc/(.*)     -                       [L,QSA]
        RewriteRule ^/favicon.ico   -                       [L,QSA]
        RewriteRule ^(.*)$          /index.php?__path__=$1  [B,L,QSA]

        SetEnv PHABRICATOR_ENV custom/myconfig

        # 以下省略....

再起動します。

sudo /etc/init.d/apache2 restart

注意事項:rewirteがインストールされていない

起動時にrewriteを導入していないと、以下のエラーになります。

Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration
Action ‘configtest’ failed.
The Apache error log may have more information.
…fail!

以下のコマンドでインストールします。

sudo a2enmod rewrite

こんな感じでインストールされました。

Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart

3. Setupウィザードを実行

http://192.168.56.101/にアクセスして、Setupを行います。
色々設定される途中で、エラーが出るので修正していきましょう。

エラーが出ないように修正をして、以下のように表示されたらとりあえずOKです。

>>> SUCCESS! —————————————————————–

Congratulations! Your setup seems mostly correct, or at least fairly reasonable.

*** NEXT STEP ***
Edit your configuration file (conf/custom/myconfig.conf.php) and remove the ‘phabricator.setup’ line to finish installation.

修正が完了、myconfig.conf.phpのphabricator.setupfalseに設定しておきます。

注意事項:timezoneの設定

<<< *** FAILURE! *** >>>
Setup failure! Your configuration fails to specify a server timezone. Either set ‘date.timezone’ in your php.ini or ‘phabricator.timezone’ in your Phabricator configuration. See the PHP documentation for a list of supported timezones:

/etc/php5/apache2/php.initimezoneの設定もれなので追加してapacheを再起動します。

date.timezone = 'Asia/Tokyo'

注意事項:ドメインの問題

<<< *** FAILURE! *** >>>
You must host Phabricator on a domain that contains a dot (‘.’). The current domain, ‘localhost’, does not have a dot, so some browsers will not set cookies on it. For instance, ‘http://example.com/ is OK, but ‘http://example/&#8217; won’t work. If you are using localhost, create an entry in the hosts file like ‘127.0.0.1 example.com’, and access the localhost with ‘http://example.com/&#8217;.

phabricator.base-urihttp://localhostなどのようにドットを持たないURLを指定しているとエラーになってしまいます。
localhost.comなど.を含むURLにする必要があります。

# となるとlocalhostで単純に出来ないのでlocalhost.comとか作って/etc/hostsを弄ったりするはめに…

注意事項:SQLの更新

<<< *** FAILURE! *** >>>
Setup failure! You haven’t run ‘bin/storage upgrade’. See this article for instructions:

自分の環境では初期セットアップでも出た場合と出ない場合がありましたが…。
設定ガイドに従って以下を実行してstrageを初期化します。

prepro:/opt/phabricator/$ ./bin/storage upgrade

注意事項:メール設定

<<< *** FAILURE! *** >>>
Setup failure! You don’t have a ‘sendmail’ binary on this system but outbound email is configured to use sendmail. Install an MTA (like sendmail, qmail or postfix) or use a different outbound mail configuration. See this guide for configuring outbound email:

メール設定が行われていないときに発生します。
必要に応じて任意のメールサーバーを設定します。
ここではとりあえず無効化の設定を myconfig.config.phpに設定を行っています。
詳しくはConfiguring_Outbound_Emailを参考にしてください。

MySQLのタイムアウト設定

*** NOTE: Your MySQL connect timeout is very high (60 seconds). Consider reducing it
to 5 or below by setting ‘mysql.connect_timeout’ in your php.ini.

タイムアウトが長すぎると警告されているので5秒辺りにphp.iniを修正します。

mysql.connect_timeout = 5

注意事項:セットアップ完了で初期遷移後のエラー

This install of Phabricator is configured as ‘localhost.com’ but you are accessing it via ‘192.168.56.101’. Access Phabricator via the primary configured domain.

ドアクセス質得るドメインとmyconfig.config.php上で定義したphabricator.base-uriが違うとこのエラーが出ます。同じドメインに設定しておきましょう。

4.アカウントの作成

http://192.168.56.101/へ遷移すると、アカウントの入力を求められます。
phabricator自体はFaebookやGoogleへのOAuthをサポートしていますが、デフォルトではuserId/Passwordの認証のみになります。
管理者権限があればWEBからアカウントの制御を行えますが、初期ユーザはCLIで作成する必要があります。

prepro@/opt/phabricator/phabricator$ bin/accountadmin 

でウィザードが起動して新規ユーザを作成します。

アカウント関連に関してはConfiguring_Accounts_and_Registrationを参照してください。

以上で、環境構築は完了です。
これで起動して確認する事が可能ですが、次回はその他の設定を行います。

Posted in program | タグ: , , , | 2 Comments »

MeteorでSession.setしてもリアクティブ処理されなかった

Posted by hikaruworld : 2012 9月 13

Meteor0.4でSession#setで設定時のリアクティブ処理の伝搬がうまくいかないなぁと思ってソース確認してたら、
こんな処理になっていました。

//Session.js
//...
set: function (key, value) {
 var self = this;
 var old_value = self.keys[key];
 if (value === old_value)
    return;
//...

===でインスタンス比較して変更されていない場合は処理しない実装になってますね。
むぅ、これはセッション上にオブジェクトはやめとけてきな感じ?
わかるけど、わかるけど…。オブジェクト渡したいんですよ。

どうするか迷ったけど、undersocre.jsのcloneで回避するようにしました。微妙….

以上です。

Posted in program | タグ: | Leave a Comment »

SublimeText2のPackageControlをインストール(したらあいかわらずproxyでこけたでござる)

Posted by hikaruworld : 2012 9月 12

SublimeText2というのを最近よく聞くのでちょっと試してみました。
ダウンロードはこちらから。

Python製というのが素敵ですね。
Win/Mac/Linuxと一通り準備されていますが、今回はWindows7にDevBuild版のPortableVersionをインストールしています。

詳細な使い方やカスタマイズ方法はほかに譲るとして、
プラグインの管理で使うSublimePackageControlをを導入しようとしたちょっとはまったのでメモしておきます。

Sublime Package Controlのインストール

SublimeText2を起動し、View => Show Console でコンソールを立ち上げます。

以下のコマンドをコピーして(ワンライナーです)コンソールに貼り付けて実行します。

import urllib2,os; pf='Package Control.sublime-package';ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler({}))); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

するとこんなエラーになってしまいます。

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".\urllib2.py", line 126, in urlopen
  File ".\urllib2.py", line 391, in open
  File ".\urllib2.py", line 409, in _open
  File ".\urllib2.py", line 369, in _call_chain
  File ".\urllib2.py", line 1161, in http_open
  File ".\urllib2.py", line 1136, in do_open
urllib2.URLError: <urlopen error [Errno 11004] getaddrinfo failed>

proxyでこけてます。
というわけで、urlilb2.ProxyHandlerの設定をしてから実行します。
こんな感じ。

import urllib2,os; pf='Package Control.sublime-package';ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler({'http': 'http://proxy.com:8080'}))); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

これでインストールが無事完了するはずなので、SublimeText2を再起動します。

おまけ

WindowsではなくてMacで試していた時に終了ボタンを押してもアプリケーションが終了しないことがありました。
そういうときはConsoleを表示してexit()と実行してみます。

その他のパッケージのインストール

これでプラグインをインストールする環境は整ったので、好きなプラグインをインストールできる…と思ったら、
インストールしようとした瞬間にこんなエラーになります。

Package Control: There are no packages available for installation.

原因はこれのようです。
最新版にはまだマージされていないようなので、手でこの修正をマージします。

Preferences => Browse Package… でプラグインがインストールされるディレクトリを開きます。
Package Control => Package Control.pyを上記の修正に合わせて修正します。

あとはそのまま使えばOKです。

あ、当然ですが、
Preferences => Package Settings => Package Control => Settings – Default –
で、http_proxy/https_proxyの設定は行っておきましょう。

参考

Sublime Package Controlがプロキシ環境だとエラーになる

Posted in program | Leave a Comment »

Meteorで画面遷移を実装する(泥臭い感じ)

Posted by hikaruworld : 2012 9月 12

最近Meteorで遊んでいます。

簡単にプログラムできて楽しいのですが、
Meteorは基本的には画面遷移を持たない構成が前提になっているらしく、
画面遷移を実装するためには少し工夫する必要があります。

Meteorのテンプレート機能にはif文などの制御文を書く事が可能です。
今回はこの制御文とSessionを介したReactiveProggramingモデルを使って、
Sessionに状態を格納して画面遷移を制御します。

index.htmlに以下の様に定義します。

// index.html
<body>
    {{> state}}
</body>

<template name="state">
    {{#if state_is "login"}}{{> login}}{{/if}}     // LOGIN状態の場合
    {{#if state_is "main"}}{{> main{{/if}}       // MAIN状態の場合
</template>

<template name="login">
    <h3>ログイン</h3>
</template>

<template name="main">
    <h3>メイン画面</h3>
</template>

javascriptでstate_isの関数を定義します

// index.js
/** 引数に指定した状態とSessionに格納した状態が同じ場合にtrueを返す */
Template.state.state_is = function(state) {
    return Session.get("STATE") === state;
}

あとは、Sessionに状態を設定すると画面が遷移します。
デベロッパーツールなどのjavascriptコンソールでSession#setで値を設定してみます。

Session.set("STATE", "login");
Session.set("STATE", "main");

ちなみにmeteor.comにデプロイもしてみました。

ちなみにこちらのサイト(英語)が参考になりました。

以上です。

Posted in program | タグ: , | Leave a Comment »

meteorをhomebrewでインストールする

Posted by hikaruworld : 2012 9月 12

Meteor はcurlで簡単にインストールできるのですが、
Macだとhomebrewでインストールできると色々と楽です。

何か方法がないかなーと思って探していると、issues16を発見。
GistにFormulaが公開されていたので拝借します。

ここで公開されているバージョンは、0.3.8のため、0.4.0に修正しておきます。
sha1の修正も必要です。

# git clone https://gist.github.com/3072321
require 'formula'

class Meteor < Formula
  homepage 'http://www.meteor.com'
  url 'http://d3sqy0vbqsdhku.cloudfront.net/meteor-package-Darwin-x86_64-0.4.0.tar.gz'
  sha1 'eeddf0a529e6664e99cb10e8335389b53e95abde'

  def install
    libexec.install(Dir['{.*,*}'] - ['.', '..']) # includes dotfiles
    (bin+'meteor').write <<-EOS.undent
#!/bin/bash
exec "#{libexec}/bin/meteor" "$@"
EOS
  end

  def test
    system "#{bin}/meteor", '--version'
  end
end

自分のgithubにupしたので、tapでgithubに登録しておきます。

brew tap hikaruworld/local

あとは、インストールするだけでOK。

brew install meteor

以上です。

Posted in program | タグ: , | Leave a Comment »