如果你用ECS来管理日常代码,一定会有这样一个过程:
step 1:
git clone user@domain.com:/my/git/repo/dir
step 2:
git clone http://domain.com/my-repo.git
step 3:
浏览器里输入 http://domain.com/my-repo.git 即时浏览源码和git提交记录
大部分人,停止在了第一步,因为第二步、第三步,还挺麻烦。特别是第二步。
周末再次(大约1年前已经折腾过一次,惜败)尝试安装gitlab-ce (community-edition),再次,惜败!于是我决定放弃 gitlab,开辟新大陆。
GitPHP
在线浏览源码和 git 提交记录的工具。基于PHP编写,很轻量,无需数据库,权限控制功能相当强大。
Git-Lighttp
以 http 的形式对外提供 git clone push 服务。基于Rudy编写,无需数据库。厌倦了基于 ssh 服务提交代码的话,不妨一试。
两个工具都很靠谱,安装文档比较缺乏,需要动用你的钻研精神哦。下面就重点介绍一下。
安装很简单,直接从 git clone 即可。
GitPHP 和 Git-Lighttp 都支持权限控制,下面重点说明。
GitPHP的配置(包括权限控制)都在源码的 config 目录下
[ray@aliyun config]# tree
.
|-- gitphp.conf.php
|-- projects.conf.php
`-- users.conf.php
核心配置包括:
gitphp.conf.php
---
// 注意:php 必须具有对 git 仓库目录的访问权限
$gitphp_conf['projectroot'] = './your/git/repo/dir';
projects.conf.php
---
可以不动
projects.conf.php
---
$gitphp_users = array(
array(
'username' => 'ray',
'password' => 'woshidachunlv'
),
array(
'username' => 'jack',
'password' => 'iloverose'
),
array(
'username' => 'rose',
'password' => 'youjumpijump'
)
);
用户名密码配置好后,去每一个 git 数据仓库的 .git/config 文件里面增加项目 (project) 级别的权限控制。例如 vue.git 项目中,给 ray 增加可读的权限:
[ray@aliyun vue.git]# pwd
/web/domain.com/git/repo/vue.git/
[ray@aliyun vue.git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[gitphp]
category = Vue
description = Vue
owner = Evan You
cloneurl = http://git.domain.com:4096/vue.git
pushurl = http://git.domain.com:4096/vue.git
bugpattern = "/#([0-9]+)/"
bugurl = http://bug.domain.com/projects/gitphp/issues/${1}
compat = false
website = http://www.domain.com/
allowedusers = ray
不配置 [gitphp] 的话,默认对所有人可见。
它依赖 htpasswd 文件来做权限控制。运行 htpasswd 命令能够添加用户,将结果放到 repo 根目录的 htpasswd 文件里。下面是我的配置:
[ray@aliyun repo]# pwd
/web/domain.com/git/repo
# 这是我的数据仓库位置
[ray@aliyun repo]# tree -L 1
.
|-- htpasswd
|-- gitphp.git
|-- vue.git
`-- vue-cli.git
[ray@aliyun repo]# cat htpasswd
ray:.za9933xxooB6
ray 就是我的用户名,在 clone 和 push 的时候会用到。
例如,在我的 Mac 上使用 git 仓库:
[ray@mac repo]# git clone http://git.domain.com:4096/vue.git
Cloning into 'vue'...
Username for 'http://git.domain.com:4096': ray
Password for 'http://ray@git.domain.com:4096':
remote: Counting objects: 16183, done.
remote: Compressing objects: 100% (4274/4274), done.
remote: Total 16183 (delta 11817), reused 16172 (delta 11811)
Receiving objects: 100% (16183/16183), 5.33 MiB | 487.00 KiB/s, done.
Resolving deltas: 100% (11817/11817), done.
Checking connectivity... done.
其实,还是 gitlab 省事,无奈 gitlab-ce 就不是诚心给人用,太难安装了。 如果你有钱,专门买个预装了 Gitlab 的 ECS,忒方便。 或者买个 预装 Ubuntu 的 ECS, 然后安装一个 Docker,最后搞个 Gitlab 的 Docker 发布包装一下就行了。
自己装一个 Git Server 是长久以来的打算,终于完成了,之后的代码管理可以更规范一些,不错不错。