1. 程式人生 > >docker之快速部署gogs git

docker之快速部署gogs git

passwd enable 最簡 max ict vpd network https nag

前言
  • gogs簡介

    • Gogs 是一款極易搭建的自助 Git 服務。
    • Gogs 的目標是打造一個最簡單、最快速和最輕松的方式搭建自助 Git 服務。使用 Go 語言開發使得 Gogs 能夠通過獨立的二進制分發,並且支持 Go 語言支持的 所有平臺,包括 Linux、Mac OS X、Windows 以及 ARM 平臺。
  • 為什麽使用gogs
    • gogs輕量
    • gogs自帶git update
    • gogs操作簡潔

基於docker快速搭建

  • 準備數據庫
    • 如果之前沒有數據庫,可以使用docker快速部署mysql或mariadb
mkdir -p ~/mysql/data ~/mysql/logs ~/mysql/conf
docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
  • 配置數據庫
MariaDB [(none)]> create database gogs default character set utf8;
MariaDB [(none)]> grant all on gogs.* to ‘gogs‘@‘%‘ identified by ‘gogspass‘;
  • 如果已經有docker搭建數據庫,可以使用下面的方法通過docker自有的網絡互通,當然簡單的方法就是通過訪問外網的端口使用數據庫
docker network ls
docker network connect dockeronlyofficenextcloudmysql_onlyoffice gogs
docker run -itd --name=gogs -p 10022:22 -p 10080:3000 -e TZ=Asia/Shanghai -v /volume1/docker/gogs:/data gogs/gogs

gogs配置

  • docker啟動後基於web配置
  • http://IP:10080/install
    技術分享圖片

技術分享圖片

gitlab vs gogs 資源消耗

  • gitlab
    • 技術分享圖片
  • gogs
    • 技術分享圖片

配置文件查看

cat gogs/conf/app.ini

APP_NAME = Aiker Edward
RUN_USER = git
RUN_MODE = prod

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

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

[server]
DOMAIN           = gogs.abc.com
HTTP_PORT        = 3000
ROOT_URL         = http://gogs.abc.com/
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    = true
SHOW_REGISTRATION_BUTTON = false

[picture]
DISABLE_GRAVATAR        = false
ENABLE_FEDERATED_AVATAR = true

[session]
PROVIDER = file

[log]
MODE      = file
LEVEL     = Info
ROOT_PATH = /data/log

[security]
INSTALL_LOCK = true # true關閉web配置向導,false打開web配置向導
SECRET_KEY   = NbSgKURfSaFxcdxW

技術分享圖片

配置基於nginx ssl的反向代理

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name gogs.abc.com;

    ssl_certificate /usr/syno/etc/certificate/ReverseProxy/3a2b92d0-ea43-4c88-a7a0-e8be86104850/fullchain.pem;

    ssl_certificate_key /usr/syno/etc/certificate/ReverseProxy/3a2b92d0-ea43-4c88-a7a0-e8be86104850/privkey.pem;

    add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload" always;

    location / {
        proxy_set_header        Host                $http_host;
        proxy_set_header        X-Real-IP           $remote_addr;
        proxy_set_header        X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto   $scheme;
        proxy_intercept_errors  on;
        proxy_http_version      1.1;

        proxy_pass http://localhost:10080;

    }

}

這樣就可以通過https+域名訪問了。
技術分享圖片

docker之快速部署gogs git