介绍

Have you used Gogs? It’s great. Gogs is a Git service, much like GitHub and GitLab, but written in Go. It’s a immensely lighter than GitLab and it’s not lacking at all in features.

Gogs仓库构建

gogs安装方式很多,二进制安装/源码安装/docker安装,具体细节可以查看官网或者github

这里我选择的是docker-compose安装,使用docker-compose方便快捷.

安装docker

这里不便赘述查看先前写的安装kubernetes里面的安装docker步骤

当然也可以选择官网安装

curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
$ cd /data/gogs
$ vi docker-compose.yml
version: '2'
services:
  gogsdb:
    container_name: gogsdb
    image: mariadb:10.2.18 
    volumes:
      - "/usr/local/mariadb/data:/var/lib/mysql"
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: $PASSWORD
      MYSQL_DATABASE: gogs
      MYSQL_USER: $USER
      MYSQL_PASSWORD: $PASSWORD
  gogs:
    container_name: gogs
    depends_on:
      - gogsdb
    image: gogs/gogs
    volumes:
      - /var/gogs:/data
    links:
      - gogsdb
    ports:
      - "10080:3000"    #暴露的http端口
      - "10022:22"      #暴露的ssh端口,按照自己的喜好更换     
    restart: always
  jenkins:
    image: jenkins/jenkins:2.183
    container_name: jenkins
    restart: always
    ports:
      - 18080:8080
      - 50000:50000
    links:
      - gogs:gogs
    volumes:
      - /data/jenkins:/var/jenkins_home
docker-compose up -d
docker-compose down -v

gogs配置文件

部署成功后,直接访问gogs项目,然后开始进行配置

首先是数据库的配置按照配置文件写入即可

其次是应用的基本设置,这个设置比较重要,关系到git clone的操作参数

其中应用名称,可以写公司的名称,比如gogs;仓库的根目录/data/git/gogs-repositories,可以选择默认

域名选择以后想要git clone的域名,比如gogs.wangke.co,ssh端口号填写自己映射的端口比如10022

http端口号这个必须写3000,这个监听在容器内,不然容器起不来.

应用Url,填写git clone的http服务的url,比如http://gogs.wangke.co:10080/,这里端口填写自己对外映射的端口.这里我做了一次反向代理了,使用nginx反向代理了本地的http://127.0.0.1:10080.所以把端口省略了.

admin选项自己填写即可.以下是生成的app.ini配置文件.

APP_NAME = Gogs
RUN_USER = git
RUN_MODE = prod

[database]
DB_TYPE  = mysql
HOST     = gogsdb:3306
NAME     = gogs
USER     = $USER
PASSWD   = $PASSWORD
SSL_MODE = disable
PATH     = data/gogs.db

[repository]
ROOT = /data/git/gogs-repositories

[server]
DOMAIN           = gogs.wangke.co
HTTP_PORT        = 3000
ROOT_URL         = http://gogs.wangke.co/
DISABLE_SSH      = false
SSH_PORT         = 10022
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 = /app/gogs/log

[security]
INSTALL_LOCK = true
SECRET_KEY   = RNcQAMf374kihMd

改变ssh端口为22

在Docker和本地系统内的Gogs之间共享端口22

cd /data/gogs
sed -i "/10022/22/g"  docker-compose.yml
sed -i "/SSH_PORT         = 10022/SSH_PORT         = 22/g" /var/gogs/gogs/conf/app.ini
docker restart mygogs