
上一篇博客中介绍了如何安装部署Phabricator,本以为安装完成之后就可以愉快的使用了,但是没想到只是完成了一半,打算迁徙几个代码库进来试试,结果又踩了不少坑,在安装部署完成的基础之上还需要配置不少东西才能真正的用起来,Phabricator看起来是很不错,但是作为一个工具,不得不说使用门槛还是偏高(可能是我太菜了[/捂脸]),最后终于用上了,简单总结分享一下吧
Repository Hosting
Phabricator支持Git、SVN以及Mercurial在SSH以及HTTP(Mercurial不支持HTTP)协议下进行代码托管,具体可以参见官方文档,这里只介绍Git+SSH的方式,文档比较长,但是简化翻译后一共要进行如下几步操作:
创建用户
Phabricator需要设置三个账户:
daemon-user用于启动phd守护进程,这里我直接用了rootwww-user作为WEB服务运行的用户,安装部署的时候已经默认了apache无需手动设置vcs-userGit操作相关的用户,这里我用了git
1 | # 添加git用户 |
修改配置,启动服务1
2
3[phabricator]# ./bin/config set phd.user root
[phabricator]# ./bin/phd start
[phabricator]# ./bin/config set diffusion.ssh-user git
注:
1.The second field (which is the password field) must not be set to !!. This value will prevent login. If it is set to !!, edit it and set it to NP (“no password”) instead
2.务必注释掉sudoer中的Defaults requiretty
配置SSHD
为Phabricator单独配置一个sshd到2222端口上,当然你可以放到任意一个端口,如果你觉得很不爽,也可以阅读官方文档进行一些特殊的设置。1
2
3
4
5
6
7
8# 设置端口号为2222
./bin/config set diffusion.ssh-port 2222
# 编辑脚本
cd ~your/phabricator/path
cp ./resources/sshd/phabricator-ssh-hook.sh /usr/libexec/phabricator-ssh-hook.sh
chmod 0755 /usr/libexec/phabricator-ssh-hook.sh
vim /usr/libexec/phabricator-ssh-hook.sh
看起来大概这样:1
2
3
4
5
6
7
8
9
10
11
12
13
14#!/bin/sh
# NOTE: Replace this with the username that you expect users to connect with.
VCSUSER="git"
# NOTE: Replace this with the path to your Phabricator directory.
ROOT="/var/www/html/phabricator"
if [ "$1" != "$VCSUSER" ];
then
exit 1
fi
exec "$ROOT/bin/ssh-auth" $@
创建编辑sshd配置文件1
vim /etc/ssh/sshd_config.phabricator
1 | # NOTE: You must have OpenSSHD 6.2 or newer; support for AuthorizedKeysCommand |
执行/usr/sbin/sshd -f /etc/ssh/sshd_config.phabricator启动sshd
注:
Both the script(phabricator-ssh-hook.sh) itself and the parent directory the script resides in must be owned by root, and the script must have 755 permissions
Import repository
完成上面的步骤之后,就可以自己新建仓库了,创建仓库很简单就不啰嗦了,这里讲一下如何导入一个现有的代码库到Phabricator中,步骤如下:
添加Credentials
进入Application->Passphrase->Create Credential,添加一个SSH Private Key将本机的SSH密钥对加入系统,同时将Public Key放到需要克隆的远程仓库中例如GitHub或者原来Gerrit所在的机器
导入代码
- 进入
Diffusion->Create Repository->Create Git Repository创建一个仓库 - 找到新建的仓库,点击
Manage Repository->URIs->Add New URI,将远程仓库地址填写到URI中,设置I/O Type为Observe模式 Set Credentials选中刚才添加的Credentials- 回到
Basics中Activate Repository,此时可以在状态中看到正在导入,等待导入完成 - 在导入完成之后,编辑刚才
Observe模式的那个URI,设置I/O Type为No I/O
注:
官方文档中写的是Disable掉Observe的那个URI,实际上应该是设置I/O Type为No I/O
Clone & Commit
进入Settings->Personal Settings->Edit->SSH Public Keys把平时开发用的机器的Public Key放进去,到这里,就可以用git clone指定的代码库了。不过还没完,你还得安装学习一下如何用Arcanist提交代码1
2
3
4
5# 下载到任何目录
mdkir cd /usr/local/phabricator
cd /usr/local/phabricator
git clone https://github.com/phacility/libphutil.git
git clone https://github.com/phacility/arcanist.git
第一次使用的时候,会提示输入一个Token,直接根据提示从你的Phabricator URL中就能获取到,另外别忘了设置一下环境变量,vim /etc/profile.d/pha.sh1
export PATH=$PATH:/usr/local/phabricator/arcanist/bin
顺便可以设置一下开机启动啥的这里就不写了,Arcanist我简单的使用了一下,大概有这些好处:
- 让你的提交信息变得更规范
- 提交时就能设置好review相关的参数
- 直接用命令行就可以查看多个提交review的进度(这个很爽)
- 命令行直接合并代码
简而言之就是更加快捷高效,命令并不难掌握,可以参考一下这个链接学习一下,如果用过git上手这个应该很快。
最后,如果你只是自己玩玩或者在一个个人项目中使用Phabricator,别忘了设置differential.allow-self-accept为true ,下一篇我打算试试集成一个合适的CI系统进来,敬请期待~
EOF