|
前沿:
对于代码库感触有点多,用过redmine(差点忘了名字),还有就是gitweb,最后就是gitlab 。 gitlab是我用的很舒服的东西,在2012就接触了,当时开发水平见不得人,主要上传的还是常用安装配置脚本、简单的cs端,及ganglia插件之类的。
在以前的以前的公司,我也负责维护过gitlab,但是那边的很多需求,比如自动化测试,提供git-shell接口啥的,需要懂ruby,算了,玩不转。。so, 就把这个事给推了,让开发自己搞了。 据说部门直接招了一个rubu搞gitlab的二次开发 ! 来了新公司,这边的代码库用的实在是不习惯,这个星期自己配置了gitlab用来上传代码和管理。
申请了一个服务器,居然是ubuntu ! 是别的开发剩下的,算了,能用就挺好的。再跟他们扯皮,估计就直接给你一个kvm主机了。
基本的环境,你懂的!
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev 配置ruby环境,其实个人建议直接apt-get install ruby 就好了,编译实在是墨迹!
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392
./configure
make
sudo make install
安装配置 bundler
sudo gem install bundler
# 创建用户
sudo adduser --disabled-login --gecos 'GitLab' git
# 登录第三步创建的 git 用户,克隆 gitlab-shell
sudo su git
cd /home/git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
cp config.yml.example config.yml
# 给主机域名.例如 'http://domain.com/',本地局域网安装的话默认localhost也可以本地的ip地址,我这边直接用localhost
vim config.yml
# 开始安装.(这里就等吧~ )
./bin/install
# 软件源安装 mysql 数据库,过程中会让你输入两次 mysql root 用户的密码,牢记!
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
mysql -u root -p
CREATE USER 'gitlab'@'localhost'>
# 创建 gitlabhq_production 数据库
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# 将 gitlabhq_production 数据库的增删改查 等权限赋予 gitlab 用户
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,>
# 退出 mysql 数据库
mysql> \q
# 尝试用 gitlab 用户连接 gitlabhq_production 数据库,登录成功(注:出现 mysql>)说明数据库配置完成.
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
(提示这个,是因为你的git用户的git命令没有在sudoers权限授权的原因。)
# gitlab 要安装到 git 用户的 home 目录下.
cd /home/git
# 克隆 gitlab 项目,并切换分支, 配置文件
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
# 切换到 gitlab 的 5.3 分支.
sudo -u git -H git checkout 5-3-stable
cd /home/git/gitlab
# 复制 gitlab 的示例配置文件到指定目录
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# 如果用的不是本地服务器,更改 localhost 为 gitlab 的服务器域名
sudo -u git -H vim config/gitlab.yml
# 确保当前用户对 gitlab 的 log 和 tmp 文件有读写权限.
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX public/uploads
sudo -u git -H cp config/puma.rb.example config/puma.rb
# 找到其中有一行 # workers 2,去掉前面的 # 并将 2 改为 3.
sudo -u git -H vim config/puma.rb
# 配置 gitlab 的全局设置.
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
# 复制示例Mysql配置文件到指定目录
sudo -u git cp config/database.yml.mysql config/database.yml
# 修改里面的 root 为 gitlab, 密码为创建的 gitlab mysql 用户密码
sudo vim config/database.yml
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9.4'
sudo -u git -H bundle install --deployment --without development test postgres
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# 下载 gitlab 的 开始/停止 脚本,并且加入当前用户的可执行权限.
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
# 添加 gitlab 的开机启动
sudo update-rc.d gitlab defaults 21
# 检查 gitlab 的状态和环境配置是否正确.
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
# 启动 gitlab
sudo service gitlab start
# 或者
sudo /etc/init.d/gitlab restart
好了,这样gitlab的配置都算ok啦~ 咱们现在搞搞gitlab最主要的页面部分了!
安装配置nginx,你懂的~
(因为我这边的nginx有点复杂参杂着lua和uwsgi,所以折腾的时候费了不少时,其实很简单的问题,让我折腾复杂了。。。呵呵)
apt-get install nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
nginx.conf的server块的配置 !
server {
listen 80; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good> server_name ceshi.xiaorui.cc; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}
好了,咱们就可以登录了!
默认的帐号和密码是
admin@local.host
5iveL!fe
这是我刚才上传的代码,代码的样式主题还是很时尚的。
代码的高亮显示效果,还不错哈~
gitlab针对ldap的认证,很容易就可以实现,毕竟帐号管理自己做太麻烦啦,联合windows ad的话,就好办多啦。
vim /home/git/gitlab/config/gitlab.yml
## LDAP settings
ldap:
enabled: true
host: '10.58.1.33'
base: '_ruifengyun'
port: 636
uid: 'sAMAccountName'
method: 'ssl' # "ssl" or "plain"
bind_dn: ''
password: 'xxx'
我这边gitlab的邮件提醒不好用,咱们可以直接用smtp的方式!
cd /home/git/gitlab/
vi config/environments/production.rb
在# config.action_mailer.delivery_method = :sendmail下加入
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'ruifengyun@gmail.com',
:password => 'password',
:authentication => :plain,
:enable_starttls_auto => true
}
编辑config/gitlab.yml
vi config/gitlab.yml
对应修改一下配置
email: from: ruifengyun@gmail.com
protocol: http
官方给了例子,POST过来的是一个json串,咱们在服务器端接收后,就可以做自己喜欢的事情了。
{ "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"user_id": 4,
"user_name": "John Smith",
"repository": {
"name": "Diaspora",
"url": "git@localhost:diaspora.git",
"description": "",
"homepage": "http://localhost/diaspora",
},
"commits": [
{
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"message": "Update Catalan translation to e38cb41.",
"timestamp": "2011-12-12T14:27:31+02:00",
"url": "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"author": {
"name": "Jordi Mallach",
"email": "jordi@softcatala.org",
}
},
// ...
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://localhost/diaspora/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)",
},
},
],
"total_commits_count": 4,
};
PHP端的一个接收实现: |
|