GHProxy与Smart-Git结合部署, 以实现Git-Clone缓存功能

关于

GHProxy

基于Go的高性能,多功能,可扩展的Github代理

  • 基于Go语言实现,支持多平台
  • 使用Gin作为Web框架
  • 使用Touka-HTTPC作为HTTP客户端
  • 支持Git clone,raw,realeases等文件拉取
  • 支持Git Clone缓存(配合组件)
  • 支持Docker部署
  • 支持速率限制
  • 支持用户鉴权
  • 支持自定义黑名单/白名单
  • 基于WJQSERVER-STUDIO/golang-temp模板构建,具有标准化的日志记录与构建流程

开源于WJQSERVER-STUDIO/GHProxy

Demo

TG讨论群组

Smart-Git

基于HertZ和Go-Git实现的git clone (smart http) 转发, 完整实现git clone server(smart http)和git clone client(smart http)

  • 基于HertZ netpoll 构建, 高性能可扩展
  • 基于Go-Git实现git相关功能
  • 使用轻量级数据库BoltDB实现相关元数据管理
  • 支持缓存

开源于WJQSERVER-STUDIO/Smart-Git

部署

Docker-Compose

  1. Docker环境
1
docker -v #查看 docker 版本

使用Docker-Compose编排进行部署, 首先您需要确认您已安装Docker组件, 若未安装请参看Linux安装Docker

  1. 创建文件夹

此段以此文件夹进行演示

1
2
mkdir -p /root/data/docker_data/ghproxy
cd /root/data/docker_data/ghproxy 

配合Smart-Git

  1. 创建docker-compose.yml文件
1
touch docker-compose.yml
  1. 修改docker-compose.yml内容为以下配置
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
version: '3.9'
services:

    ghproxy:
        image: 'wjqserver/ghproxy:latest'
        restart: always
        volumes:
            - './ghproxy/log/run:/data/ghproxy/log'
            - './ghproxy/log/caddy:/data/caddy/log'
            - './ghproxy/config:/data/ghproxy/config'
        ports:
            - '7210:8080' # : 前的端口您可自行修改

            
    smart-git:
        image: 'wjqserver/smart-git:latest'
        restart: always
        volumes:
            - './smart-git/log/run:/data/smart-git/log'
            - './smart-git/config:/data/smart-git/config'
            - './smart-git/repos:/data/smart-git/repos'
            - './smart-git/db:/data/smart-git/db'
  1. 修改/root/data/docker_data/ghproxy/ghproxy/config/config.toml文件以启用Smart-Git连接器

修改[gitclone]配置块内的配置

  • mode设置为"cache"
  • smartGitAddr设置为"http://smart-git:8080"
  • ForceH2C按照需求配置
 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
[server]
host = "0.0.0.0"  # 监听地址
port = 8080  # 监听端口
sizeLimit = 125 # 125MB
H2C = true # 是否开启H2C传输 
cors = "*" # "*"/"" -> "*" ; "nil" -> "" ; 除以上特殊情况, 会将值直接传入

[httpc]
mode = "auto" # "auto" or "advanced" HTTP客户端模式 自动/高级模式
maxIdleConns = 100 # only for advanced mode 仅用于高级模式
maxIdleConnsPerHost = 60 # only for advanced mode 仅用于高级模式
maxConnsPerHost = 0 # only for advanced mode 仅用于高级模式

[gitclone]
mode = "cache" # bypass / cache 运行模式, cache模式依赖smart-git
smartGitAddr = "http://smart-git:8080" # smart-git组件地址
ForceH2C = false # 强制使用H2C连接(实验性, 可配置为true)

[pages]
mode = "internal" # "internal" or "external" 内部/外部 前端 默认内部
theme = "bootstrap" # "bootstrap" or "nebula" 内置主题
staticPath = "/data/www"  # 外部静态页面文件路径

[log]
logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径
maxLogSize = 5 # MB 日志文件最大大小
level = "info"  # 日志级别 dump, debug, info, warn, error, none

[auth]
enabled = false  # 是否开启鉴权
authMethod = "parameters" # 鉴权方式,支持parameters,header
authToken = "token"  # 鉴权Token

[blacklist]
blacklistFile = "/data/ghproxy/config/blacklist.json"  # 黑名单文件路径
enabled = false  # 是否开启黑名单

[whitelist]
enabled = false  # 是否开启白名单
whitelistFile = "/data/ghproxy/config/whitelist.json"  # 白名单文件路径

[rateLimit]
enabled = false  # 是否开启速率限制
rateMethod = "total" # "ip" or "total" 速率限制方式
ratePerMinute = 180  # 每分钟限制请求数量
burst = 5  # 突发请求数量

[outbound]
enabled = false # 是否使用自定义代理出站
url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" 支持Socks5/HTTP(S)出站传输
  1. 修改/root/data/docker_data/ghproxy/smart-git/config/config.toml(可选)

可根据需求修改[cache]配置块内的配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[server]
host = "0.0.0.0" # 监听地址
port = 8080  # 监听端口
baseDir = "/data/smart-git/repos" # 缓存文件夹

[log]
logfilepath = "/data/smart-git/log/smart-git.log"  # 日志存储位置
maxlogsize = 5 # MB
level = "info" # dump, debug, info, warn, error, none

[Database]
path = "/data/smart-git/db/smart-git.db" # 数据库存储位置

[cache]
expire = "1h" # 缓存过期时间
expireEx = "10m" # 过期延长时间(当hash检查后发现未过期, 增加的时间)
  1. 启动容器
1
docker compose up -d

启动成功后, 反代:7210即可

无Smart-Git

  1. 创建docker-compose.yml文件
1
touch docker-compose.yml
  1. 修改docker-compose.yml内容为以下配置
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
version: '3.9'
services:

    ghproxy:
        image: 'wjqserver/ghproxy:latest'
        restart: always
        volumes:
            - './ghproxy/log/run:/data/ghproxy/log'
            - './ghproxy/log/caddy:/data/caddy/log'
            - './ghproxy/config:/data/ghproxy/config'
        ports:
            - '7210:8080' # : 前的端口您可自行修改
  1. 启动容器
1
docker compose up -d

启动成功后, 反代:7210即可

二进制文件部署

配合Smart-Git

后续更新

无Smart-Git

一键脚本依赖于systemd

一键部署脚本:

1
wget -O install.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/install.sh && chmod +x install.sh &&./install.sh

部署后前端样式

Bootstrap主题

ghproxy-demo.png ghproxy-demo-dark.png

Nebula主题

nebula-dark-v2.3.0.png nebula-light-v2.3.0.png

结语

若您有所疑问, 请畅所欲言, 我们会尽可能详细的为您解答

我们感谢所有用户的支持与反馈,并期待 GHProxy 能为您带来更大的便利和效率!若此项目对您有所帮助,请不要忘记 star 本项目,您的支持是我们前进的动力!