Total Pageviews

Wednesday, 29 June 2016

a painless self-hosted Git service- gogs

Gogs (Go Git Service) is a painless self-hosted Git service. 

Gogs - Go Git Service Build Status Crowdin Gitter

  1. Due to testing purpose, data of try.gogs.io was reset in Jan 28, 2015 and will reset multiple times after. Please do NOTput your important data on the site.
  2. The demo site try.gogs.io is running under develop branch.
  3. If you think there are vulnerabilities in the project, please talk privately to u@gogs.io. Thanks!
  4. If you're interested in using APIs, we have experimental support with documentation.
  5. If your team/company is using Gogs and would like to put your logo on our website, contact us by any means.

Purpose

The goal of this project is to make the easiest, fastest, and most painless way of setting up a self-hosted Git service. With Go, this can be done with an independent binary distribution across ALL platforms that Go supports, including Linux, Mac OS X, Windows and ARM.

Overview

Features

  • Activity timeline
  • SSH and HTTP/HTTPS protocols
  • SMTP/LDAP/Reverse proxy authentication
  • Reverse proxy with sub-path
  • Account/Organization/Repository management
  • Repository/Organization webhooks (including Slack)
  • Repository Git hooks/deploy keys
  • Repository issues, pull requests and wiki
  • Add/Remove repository collaborators
  • Gravatar and custom source
  • Mail service
  • Administration panel
  • Supports MySQL, PostgreSQL, SQLite3 and TiDB (experimental)
  • Multi-language support (18 languages)

System Requirements

  • A cheap Raspberry Pi is powerful enough for basic functionality.
  • 2 CPU cores and 1GB RAM would be the baseline for teamwork.

Browser Support

  • Please see Semantic UI for specific versions of supported browsers.
  • The official support minimal size is 1024*768, UI may still looks right in smaller size but no promises and fixes.

Installation

Make sure you install the prerequisites first.
There are 5 ways to install Gogs:

Tutorials

Screencasts

Deploy to Cloud

Software and Service Support

Product Support

Acknowledgments

  • Router and middleware mechanism of Macaron.
  • System Monitor Status is inspired by GoBlog.
  • Thanks lavachen and Rocker for designing Logo.
  • Thanks Crowdin for providing open source translation plan.
  • Thanks DigitalOcean for hosting home and demo sites.
  • Thanks KeyCDN for providing CDN service.

Contributors

from https://github.com/gogits/gogs/
----------------

Install Gogs

The general way to install Gogs:
# Download and install dependencies
$ go get -u github.com/gogits/gogs (此步骤耗时15分钟)

Test Installation

To make sure Gogs is working:
$ cd $GOPATH/bin/
$ ./gogs web
If you do not see any error messages, hit Ctrl-C to stop Gogs.

Build with Tags

A couple of things do not come with Gogs automatically, you need to compile Gogs with corresponding build tags.
Available build tags are:
  • sqlite3/tidb: SQLite3/TiDB database support
  • pam: PAM authentication support
  • cert: Generate self-signed certificates support
  • miniwinsvc: Builtin windows service support (or you can use NSSM to create a service)
Note Please follow instructions to install TiDB if you want to use it.
For example, you want to support all of them, first delete directory $GOPATH/pkg/${GOOS}_${GOARCH}/github.com/gogits/gogs and then do:
$ go get -u -tags "sqlite tidb pam cert" github.com/gogits/gogs
$ cd $GOPATH/src/github.com/gogits/gogs
$ go build -tags "sqlite tidb pam cert"

Next steps

from https://gogs.io/docs/installation/install_from_source.html
------------------------

使用 Gogs 搭建自己的 Git 服务器

下载解包

我使用的是预编译的二进制包。需要从源码编译的话,请参考一般 Go 语言项目的编译。下载后解包到你喜欢的地方,例如 /usr/share/gogs/ 或者 /home/git/gogs/。文件夹的内容如下。
$ ls /home/git/gogs/
custom  data  gogs  LICENSE  log  public  README.md  README_ZH.md  scripts  templates

运行安装

首先建立好数据库。在 Gogs 目录的 scripts/mysql.sql 文件是数据库初始化文件。执行 mysql -u root -p < scripts/mysql.sql (需要输入密码)即可初始化好数据库。
然后登录 MySQL 创建一个新用户 gogs,并将数据库 gogs 的所有权限都赋予该用户。
$ mysql -u root -p
> # (输入密码)
> create user 'gogs'@'localhost' identified by '密码';
> grant all privileges on gogs.* to 'gogs'@'localhost';
> flush privileges;
> exit;
运行 gogs web 把 Gogs 运行起来,然后访问 http://服务器IP:3000/ 来进行安装,填写好表单之后提交就可以了。 需要注意的是,0.6.9.0903 Beta 版本有个 bug,允许在关闭注册的情况下不添加管理员,这样安装完成之后将没有任何用户可以登录。所以请务必在安装界面指定一个管理员帐号。

配置调整

配置文件位于 Gogs 目录的 custom/conf/app.ini,是 INI 格式的文本文件。详细的配置解释和默认值请参考官方文档,其中关键的配置大概是下面这些。
  • RUN_USER 默认是 git,指定 Gogs 以哪个用户运行
  • ROOT 所有仓库的存储根路径
  • PROTOCOL 如果你使用 nginx 反代的话请使用 http,如果直接裸跑对外服务的话随意
  • DOMAIN 域名。会影响 SSH clone 地址
  • ROOT_URL 完整的根路径,会影响访问时页面上链接的指向,以及 HTTP clone 的地址
  • HTTP_ADDR 监听地址,使用 nginx 的话建议 127.0.0.1,否则 0.0.0.0 也可以
  • HTTP_PORT 监听端口,默认 3000
  • INSTALL_LOCK 锁定安装页面
  • Mailer 相关的选项
其中,Mailer 可以使用 Mailgun 的免费邮件发送服务,将 Mailgun 的 SMTP 配置填入到配置中就好。

nginx 反代

在 /etc/nginx/sites-available 中新建一个文件,把以下内容写入文件中。
server {
    server_name 域名或IP;
    listen 80; # 或者 443,如果你使用 HTTPS 的话
    # ssl on; 是否启用加密连接
    # 如果你使用 HTTPS,还需要填写 ssl_certificate 和 ssl_certificate_key

    location / { # 如果你希望通过子路径访问,此处修改为子路径,注意以 / 开头并以 / 结束
        proxy_pass http://127.0.0.1:3000/;
    }
}
然后进入 /etc/nginx/sites-enabled 中,执行 ln -s ../sites-available/配置文件名 启用这个配置文件。 最后重启 nginx 就好了,Ubuntu 下是 sudo service nginx restart

服务脚本

此处的服务脚本是针对 Debian 系的 init 脚本。
本节内容于 2015年12月13日 修改:修正随时间发生变化的事实。
在我写这篇文章的时候,最新版本的服务脚本似乎还有点问题,可以使用这个版本来代替。最新版本的服务脚本已经可以正常使用,请在二进制下载的 scripts 文件夹中找到对应你使用发行版的版本。将脚本放在 /etc/init.d 中,文件名为 gogs,给予执行权限并修改相关参数,以后就可以使用 sudo service gogs start 来启动服务.
-----------------------
gogs run on openshift 

Instructions

Just works use diy Join the chat at https://gitter.im/tkisme/gogs-openshift
 rhc app create diy diy-0.1 --from-code https://github.com/tkisme/gogs-openshift
 #optional choose mysql
 rhc cartridge add mysql-5.5
 #delete this is still simple
 rhc app delete diy --confirm
go use 286M,gogs use 38M
rhc app-show --gears quota

Upgrade gogs

 git remote add github git@github.com:tkisme/gogs-openshift.git
 git pull github master
 git push

Upgrade by your own

this is just for people who want to upgrade in hurry
 vi .openshift/action_hooks/start
 git commit -am "upgrade gogs"
 git push
change download_url to anyversion you want
Now it upgrade gogs to v0.9.13

Build from source

If you want build from source
rhc ssh
cd $OPENSHIFT_DATA_DIR/gogs
export GOROOT=$OPENSHIFT_DATA_DIR/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$OPENSHIFT_DATA_DIR/gocode
mkdir -p $GOPATH/src/github.com/gogits
cd $GOPATH/src/github.com/gogits
git clone -b develop https://github.com/gogits/gogs
cd gogs
go get -u ./...
go get -u -tags "sqlite redis memecache" github.com/gogits/gogs
go build -tags "sqlite redis memecache"
cd scripts
./build_linux64.sh
ls
mv output_amd64/ $OPENSHIFT_DATA_DIR
cd $OPENSHIFT_DATA_DIR
cp -r output_amd64/* gogs/
#let source go,or you have enough disk space
rm -rf gocode
cp -r output_amd64/* gogs/
rm -rf output_amd64
gear restart
FROM https://github.com/tkisme/gogs-openshift
DEMO SITE: https://gogs-gaetk.rhcloud.com
------------------
使用Gogs轻松搭建可能比GitLab更好用的Git服务平台
前言
GitHub.com已经成为首选的代码托管平台,因为它又很多很棒的功能,操作简单,几乎所有的开发者都喜欢它。但是搭建GitLab过程并没有想象中的简单,利用Bitnami当然也是一种偷懒的好选择。Gogs (Go Git Service) 是一款极易搭建的自助 Git 服务,Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 所有平台,包括 Linux、Mac OS X、Windows 以及 ARM 平台。
Gogs可能是比GitLab更好的选择.
扩展阅读
Bitnami GitLab Stack - https://bitnami.com/stack/gitlab
Bitnami GitLab Stack ships with the following software versions
  • GitLab 8.5.7
  • Apache 2.4.18
  • ImageMagick 6.7.5
  • PostgreSQL 9.4.6
  • Git 2.7.4
  • Ruby 2.1.8
  • Rails 4.2.5.1
  • RubyGems 1.8.12
Btinami GitLab Stack 安装真心简单,爽
chmod 755 bitnami-gitlab-8.5.7-0-linux.run
Gogs功能特性
  • 支持活动时间线
  • 支持 SSH 以及 HTTP/HTTPS 协议
  • 支持 SMTP、LDAP 和反向代理的用户认证
  • 支持反向代理子路径
  • 支持用户、组织和仓库管理系统
  • 支持仓库和组织级别 Web 钩子(包括 Slack 集成)
  • 支持仓库 Git 钩子和部署密钥
  • 支持仓库工单(Issue)、合并请求(Pull Request)和 Wiki
  • 支持添加和删除仓库协作者
  • 支持 Gravatar 以及自定义源
  • 支持邮件服务
  • 支持后台管理面板
  • 支持 MySQL、PostgreSQL、SQLite3 和 TiDB(实验性支持) 数据库
  • 支持多语言本地化(15 种语言)
以GitHub作为参考比较对象
特性
Gogs
Gitlab
Github
Dashboard & File Browser
Y
Y
Y
Issue Tracking, Milestones & Commit keywords
Y
Y
Y
Organizations support
N
Y
Y
Wiki
N
Y
Y
Code Review
N
Y
Y
Code Snippets
N
Y
Y
Web Hooks
Y
Y
Y
Git Hooks
Y
* Enterprise
* Enterprise
LDAP Login
Y
Y
Y
LDAP Group Sync
N
* Enterprise
* Enterprise
Branded Login Page
N
* Enterprise
* Enterprise
Language
Go
Ruby
Ruby
Platform
Cross-Platform
Linux
* Virtual Machine
License
MIT
MIT
Proprietary
Resource Usage
Low
Medium/High
Medium/High
Gogs环境要求
我以rhel6.3为例,已经属于生命周期边缘了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#安装git
yum install -y git 
git --version
git version 1.7.1
#安装mysql-server
yum install -y mysql-server
mysql --version
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
#启动数据库
service mysqld start
chkconfig mysqld on
#创建gogs数据库
cd /home/git/gogs/scripts
#mysql -u root -p < mysql.sql
mysql -u root -p
# (输入密码,无密码直接跳过)
set global storage_engine = 'InnoDB';
create database gogs character set utf8 collate utf8_bin;
create user 'gogs'@'localhost' identified by 'gogs';
grant all privileges on gogs.* to 'gogs'@'localhost';
flush privileges;
exit;
部署Gogs
Gogs是一款极易搭建的自助Git服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#创建git用户
sudo adduser git
su - git
#解压gogs
cd /home/git
unzip gogs_v0.9.13_linux_amd64.zip
ls /home/git/gogs/
gogs  LICENSE  public  README.md  README_ZH.md  scripts  templates
#启动gogs
cd /home/git/gogs
./gogs web
2016/03/31 16:23:53 [W] Custom config '/home/git/gogs/custom/conf/app.ini' not found, ignore this if you're running first time
2016/03/31 16:23:53 [T] Custom path: /home/git/gogs/custom
2016/03/31 16:23:53 [T] Log path: /home/git/gogs/log
2016/03/31 16:23:53 [I] Gogs: Go Git Service 0.9.13.0318
2016/03/31 16:23:53 [I] Log Mode: Console(Trace)
2016/03/31 16:23:53 [I] Cache Service Enabled
2016/03/31 16:23:53 [I] Session Service Enabled
2016/03/31 16:23:53 [I] SQLite3 Supported
2016/03/31 16:23:53 [I] Run Mode: Development
2016/03/31 16:23:54 [I] Listen: http://0.0.0.0:3000
#后台运行
nohup ./gogs web &
tail -f nohup.out
app.ini配置文件
注意DOMAIN和ROOT_URL这两个参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#首次安装可以打开浏览器完成剩余配置
http://ip:3000/install
#通过修改app.ini也可以
vi /home/git/gogs/custom/conf/app.ini
APP_NAME = Gogs: Go Git Service
RUN_USER = git
RUN_MODE = prod
[database]
DB_TYPE  = mysql
HOST     = 127.0.0.1:3306
NAME     = gogs
USER     = gogs
PASSWD   = gogs
SSL_MODE = disable
PATH     = data/gogs.db
[repository]
ROOT = /home/git/gogs-repositories
[server]
DOMAIN       = 172.28.70.134 
HTTP_PORT    = 3000
ROOT_URL     = http://172.28.70.134:3000/
DISABLE_SSH  = false
SSH_PORT     = 22
OFFLINE_MODE = false
[mailer]
ENABLED = false
[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL     = false
DISABLE_REGISTRATION   = false
ENABLE_CAPTCHA         = true
REQUIRE_SIGNIN_VIEW    = false
[picture]
DISABLE_GRAVATAR = false
[session]
PROVIDER = file
[log]
MODE      = file
LEVEL     = Info
ROOT_PATH = /home/git/gogs/log
[security]
INSTALL_LOCK = true
SECRET_KEY   = i4B7R55aRaFdw8j