From d94f6c0f5db1cbc595ad478749ec351ac8b276b4 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 27 Apr 2025 16:39:47 +0800 Subject: [PATCH] 25w31a --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- config/config.go | 15 +++++++++++++++ config/config.toml | 6 +++++- deploy/config.toml | 4 ++++ docs/config.md | 19 +++++++++++++++++++ proxy/{ghcr.go => docker.go} | 14 +++++++++++++- 7 files changed, 63 insertions(+), 3 deletions(-) rename proxy/{ghcr.go => docker.go} (82%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f96690..befb5e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +25w31a - 2025-04-27 +--- +- PRE-RELEASE: 此版本是v3.2.0预发布版本,请勿在生产环境中使用; +- CHANGE: 加入`ghcr`和`dockerhub`反代功能 +- FIX: 修复在`HertZ`路由匹配器下与用户名相关功能异常的问题 + 3.1.0 - 2025-04-24 --- - CHANGE: 对标准url使用`HertZ`路由匹配器, 而不是自制匹配器, 以提升效率 diff --git a/DEV-VERSION b/DEV-VERSION index 98260d3..b7b50a1 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w31t-2 \ No newline at end of file +25w31a \ No newline at end of file diff --git a/config/config.go b/config/config.go index 984dc9e..ed62121 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ type Config struct { Whitelist WhitelistConfig RateLimit RateLimitConfig Outbound OutboundConfig + Docker DockerConfig } /* @@ -143,6 +144,16 @@ type OutboundConfig struct { Url string `toml:"url"` } +/* +[docker] +enabled = false +target = "ghcr" # ghcr/dockerhub +*/ +type DockerConfig struct { + Enabled bool `toml:"enabled"` + Target string `toml:"target"` +} + // LoadConfig 从 TOML 配置文件加载配置 func LoadConfig(filePath string) (*Config, error) { if !FileExists(filePath) { @@ -244,5 +255,9 @@ func DefaultConfig() *Config { Enabled: false, Url: "socks5://127.0.0.1:1080", }, + Docker: DockerConfig{ + Enabled: false, + Target: "ghcr", + }, } } diff --git a/config/config.toml b/config/config.toml index ac1ee59..fc47ef1 100644 --- a/config/config.toml +++ b/config/config.toml @@ -58,4 +58,8 @@ burst = 5 [outbound] enabled = false -url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" \ No newline at end of file +url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" + +[docker] +enabled = false +target = "ghcr" # ghcr/dockerhub \ No newline at end of file diff --git a/deploy/config.toml b/deploy/config.toml index b88e30b..eb6d7b8 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -58,3 +58,7 @@ burst = 5 [outbound] enabled = false url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" + +[docker] +enabled = false +target = "ghcr" # ghcr/dockerhub \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index bad8c65..1a91225 100644 --- a/docs/config.md +++ b/docs/config.md @@ -70,6 +70,10 @@ burst = 5 [outbound] enabled = false url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" + +[docker] +enabled = false +target = "ghcr" # ghcr/dockerhub ``` ### 配置项详细说明 @@ -295,6 +299,21 @@ url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890" * 支持协议: `socks5://` 和 `http://` * 说明: 设置出站代理服务器的 URL。支持 SOCKS5 和 HTTP 代理协议。 +* **`[docker]` - Docker 镜像代理配置** + + * `enabled`: 是否启用 Docker 镜像代理功能。 + * 类型: 布尔值 (`bool`) + * 默认值: `false` (禁用) + * 说明: 当设置为 `true` 时,`ghproxy` 将尝试代理 Docker 镜像的下载请求,以加速从 GitHub Container Registry (GHCR) 或 Docker Hub 下载镜像。 + + * `target`: 代理的目标 Docker 注册表。 + * 类型: 字符串 (`string`) + * 默认值: `"ghcr"` (代理 GHCR) + * 可选值: `"ghcr"` 或 `"dockerhub"` + * 说明: 指定要代理的 Docker 注册表。 + * `"ghcr"`: 代理 GitHub Container Registry (ghcr.io)。 + * `"dockerhub"`: 代理 Docker Hub (docker.io)。 + ## `blacklist.json` - 黑名单配置 `blacklist.json` 文件用于配置黑名单规则,阻止对特定用户或仓库的访问。 diff --git a/proxy/ghcr.go b/proxy/docker.go similarity index 82% rename from proxy/ghcr.go rename to proxy/docker.go index c3e9ca3..8fc5f57 100644 --- a/proxy/ghcr.go +++ b/proxy/docker.go @@ -12,7 +12,19 @@ import ( func GhcrRouting(cfg *config.Config) app.HandlerFunc { return func(ctx context.Context, c *app.RequestContext) { - GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") + if cfg.Docker.Enabled { + if cfg.Docker.Target == "ghcr" { + GhcrRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") + } else if cfg.Docker.Target == "dockerhub" { + GhcrRequest(ctx, c, "https://registry-1.docker.io"+string(c.Request.RequestURI()), cfg, "dockerhub") + } else { + ErrorPage(c, NewErrorWithStatusLookup(403, "Docker Target is not Allowed")) + return + } + } else { + ErrorPage(c, NewErrorWithStatusLookup(403, "Docker is not Allowed")) + return + } } }