github
gogsglide
gogs简介
Gitlab
glide 简介
godepgogs
具体使用过程,我就不多说了,大家百度一下,资料很多。下面开始讲一下搭建过程:
安装Mysql
gogs依赖数据库,我们选择使用Mysql,网上安装方法很多,不赘述
安装gogs
安装gogs方式很多,比如
- 源码安装
- 二进制安装
- 包安装
我们这里讲的是源码安装.
前提:系统里需要先安装Go语言,如果没安装,网上教程很多
从源码安装
# 下载并安装依赖
$ go get -u github.com/gogs/gogs
# 构建主程序
$ cd $GOPATH/src/github.com/gogs/gogs
$ go build
配置与运行
接着上一步,然后输入以下指令
./gogs web
$GOPATH/src/github.com/gogs/gogs/custom/conf/app.ini
APP_NAME = Gogs
RUN_USER = fabric
RUN_MODE = prod
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306
NAME = gogs
USER = gogs
PASSWD = 123456
SSL_MODE = disable
PATH = data/gogs.db
[repository]
ROOT = /home/fabric/gogs-repositories
[server]
DOMAIN = localhost
HTTP_PORT = 3000
ROOT_URL = http://localhost:3000/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
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
ENABLE_FEDERATED_AVATAR = false
[session]
PROVIDER = file
[log]
MODE = file
LEVEL = Info
ROOT_PATH = /opt/gopath/src/github.com/gogs/gogs/log
[security]
INSTALL_LOCK = true
SECRET_KEY = UfjSHvQULpjPmJk
RUN_USER = fabricgogsgitfabric
./gogs webhttp://localhost:3000/gogs
全部默认即可.
尝试拉取代码
我们新建好仓库后,尝试拉取代码
git clone http://localhost:3000/fabric/test.git
拉取成功!
localhost:3000https://github.com/jinzhu/gorm.git
让我们继续行动吧!
nginx反向代理
我们使用Nginx来进行反向代理,以提供比较优雅的域名方式访问.
安装Nginx
老话,百度一下,你就知道哈.
配置域名
githubs
/etc/nginx/sites-availablegithubs
server {
server_name githubs.com;
listen 80;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
/etc/nginx/sites-enabledln -s ../sites-available/githubs
sudo service nginx restart
然后在hosts里面添加映射
$ vim /etc/hosts
127.0.0.1 gitbar.com
拉取代码库
git clone http://githubs.com/fabric/test.git
可以看到代码可以正常拉取了.
httpshttp
配置https
生成证书
输入以下指令生成证书
$ cd /etc/nginx/
$ sudo mkdir ssl
$ sudo openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /etc/nginx/ssl/githubs.key -out /etc/nginx/ssl/githubs.crt
最后一步会要求输入一些信息
Generating a 2048 bit RSA private key
............................................+++
...................+++
writing new private key to '/etc/nginx/ssl/githubs.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:githubs.com
Email Address []:
Common Namegithubs.com
修改nginx虚拟主机配置
修改之前生成的虚拟主机配置文件
$ vim /etc/nginx/sites-available/githubs
内容为:
server {
listen 443 ssl;
server_name www.githubs.com;
ssl on;
ssl_certificate /etc/nginx/ssl/githubs.crt;
ssl_certificate_key /etc/nginx/ssl/githubs.key;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
server {
listen 80;
server_name www.githubs.com;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
修改gogs配置
$GOPATH/src/github.com/gogs/gogs/custom/conf/app.ini server
[server]
DOMAIN = localhot
HTTP_PORT = 3000
ROOT_URL = https://githubs.com/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
OFFLINE_MODE = false
拉取代码
使用https方式拉取代码,报错:
fatal: unable to access 'https://www.githubs.com/sn/test.git/':
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
解决方案:
跳过http的ssl证书验证
git config --global http.sslverify false
再次尝试拉取,发现可以拉取代码了.
使用glide来设置代码映射
golang.org/x/*
github
$ cd /opt/gopath/src/github.com/golang
$ git clone https://github.com/golang/net.git
$ git clone https://github.com/golang/sys.git
$ ln -s /opt/gopath/src/github.com/golang /opt/gopath/src/golang.org/x
golang.org/x/netgithub.com/golang/netgolang.org/x/net
glide
安装glide
具体安装方式网上很多,我之前也写了这个,可以参照下 go包管理工具glide使用方法
设置mirrors
mg.org/x/testgithubs.com/fabric/testmirrors
$ glide mirror set https://mg.org/x/test https://githubs.com/fabric/test.git --vcs git
$ vim ~/.glide/mirrors.yaml
repos:
- original: https://mg.org/x/test
repo: https://githubs.com/fabric/test.git
vcs: git
拉取代码
glide getgithub.com/mango/template
这个文件夹首先是不存在
$ cd $GOPATH/src/github.com
$ mkdir -p mango/template
$ cd mango/template
$ glide init
$ glide get mg.org/x/test
[INFO] Loading mirrors from mirrors.yaml file
[INFO] Preparing to install 1 package.
[INFO] Attempting to get package mg.org/x/test
[INFO] --> Gathering release information for mg.org/x/test
[INFO] --> Adding mg.org/x/test to your configuration
[INFO] Downloading dependencies. Please wait...
[INFO] --> Fetching mg.org/x/test
[INFO] Resolving imports
[INFO] Downloading dependencies. Please wait...
[INFO] Exporting resolved dependencies...
[INFO] --> Exporting mg.org/x/test
[INFO] Replacing existing vendor dependencies
代码成功拉取了!
结语
mirrors
至此,整个流程就结束了,咱们可以丝滑的拉取代码了.