Skip to content

Commit c1ba893

Browse files
author
user123456
committed
完善项目
1 parent b2ebcf2 commit c1ba893

File tree

10 files changed

+485
-132
lines changed

10 files changed

+485
-132
lines changed

.github/workflows/docker-ghcr.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ jobs:
4646
4747
- name: Build and push Docker image
4848
run: |
49-
cd src
5049
docker buildx build --push \
51-
--platform linux/amd64,linux/arm64 \
50+
--platform linux/amd64,linux/arm64/v8 \
5251
--tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.VERSION }} \
5352
--tag ghcr.io/${{ env.REPO_LOWER }}:latest \
5453
--build-arg VERSION=${{ env.VERSION }} \

.github/workflows/release.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: 发布二进制文件
2+
3+
on:
4+
workflow_dispatch: # 手动触发
5+
inputs:
6+
version:
7+
description: '版本号 (例如: v1.0.0)'
8+
required: true
9+
default: 'v1.0.0'
10+
11+
jobs:
12+
build-and-release:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: 检出代码
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # 获取完整历史,用于生成变更日志
22+
23+
- name: 设置Go环境
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: '1.24'
27+
28+
- name: 获取版本号
29+
id: version
30+
run: |
31+
VERSION=${{ github.event.inputs.version }}
32+
echo "version=$VERSION" >> $GITHUB_OUTPUT
33+
echo "版本号: $VERSION"
34+
35+
- name: 生成变更日志
36+
id: changelog
37+
run: |
38+
# 获取上一个标签
39+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
40+
41+
if [ -n "$PREV_TAG" ]; then
42+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
43+
echo "## 更新内容" >> $GITHUB_OUTPUT
44+
echo "" >> $GITHUB_OUTPUT
45+
git log --pretty=format:"- %s" $PREV_TAG..HEAD >> $GITHUB_OUTPUT
46+
echo "" >> $GITHUB_OUTPUT
47+
echo "EOF" >> $GITHUB_OUTPUT
48+
else
49+
echo "changelog=## 首次发布" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: 创建构建目录
53+
run: |
54+
mkdir -p build/hubproxy
55+
56+
- name: 编译二进制文件
57+
run: |
58+
cd src
59+
60+
# Linux AMD64
61+
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-amd64 .
62+
63+
# Linux ARM64
64+
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-arm64 .
65+
66+
- name: 复制配置文件
67+
run: |
68+
# 复制配置文件
69+
cp src/config.toml build/hubproxy/
70+
71+
# 复制systemd服务文件
72+
cp hubproxy.service build/hubproxy/
73+
74+
# 复制安装脚本
75+
cp install-service.sh build/hubproxy/
76+
77+
# 复制Web资源文件(如果存在)
78+
if [ -d "src/public" ]; then
79+
cp -r src/public build/hubproxy/
80+
fi
81+
82+
# 创建README文件
83+
cat > build/hubproxy/README.md << 'EOF'
84+
# HubProxy
85+
86+
项目地址:https://github.com/sky22333/hubproxy
87+
EOF
88+
89+
- name: 创建压缩包
90+
run: |
91+
cd build
92+
93+
# Linux AMD64 包
94+
mkdir -p linux-amd64/hubproxy
95+
cp hubproxy/hubproxy-linux-amd64 linux-amd64/hubproxy/hubproxy
96+
cp hubproxy/config.toml hubproxy/hubproxy.service hubproxy/install-service.sh hubproxy/README.md linux-amd64/hubproxy/
97+
tar -czf hubproxy-${{ steps.version.outputs.version }}-linux-amd64.tar.gz -C linux-amd64 hubproxy
98+
99+
# Linux ARM64 包
100+
mkdir -p linux-arm64/hubproxy
101+
cp hubproxy/hubproxy-linux-arm64 linux-arm64/hubproxy/hubproxy
102+
cp hubproxy/config.toml hubproxy/hubproxy.service hubproxy/install-service.sh hubproxy/README.md linux-arm64/hubproxy/
103+
tar -czf hubproxy-${{ steps.version.outputs.version }}-linux-arm64.tar.gz -C linux-arm64 hubproxy
104+
105+
# 列出生成的文件
106+
ls -la *.tar.gz
107+
108+
- name: 计算文件校验和
109+
run: |
110+
cd build
111+
sha256sum *.tar.gz > checksums.txt
112+
cat checksums.txt
113+
114+
- name: 创建或更新Release
115+
uses: softprops/action-gh-release@v1
116+
with:
117+
tag_name: ${{ steps.version.outputs.version }}
118+
name: "HubProxy ${{ steps.version.outputs.version }}"
119+
body: |
120+
${{ steps.changelog.outputs.changelog }}
121+
122+
123+
## 下载文件
124+
125+
- **Linux AMD64**: `hubproxy-${{ steps.version.outputs.version }}-linux-amd64.tar.gz`
126+
- **Linux ARM64**: `hubproxy-${{ steps.version.outputs.version }}-linux-arm64.tar.gz`
127+
128+
files: |
129+
build/*.tar.gz
130+
build/checksums.txt
131+
draft: false
132+
prerelease: false
133+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
FROM golang:1.24-alpine AS builder
2-
3-
WORKDIR /app
4-
COPY go.mod go.sum ./
5-
RUN go mod download
6-
7-
COPY . .
8-
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -trimpath -o hubproxy .
9-
10-
FROM alpine
11-
12-
WORKDIR /root/
13-
14-
# 安装skopeo
15-
RUN apk add --no-cache skopeo && mkdir -p temp && chmod 700 temp
16-
17-
COPY --from=builder /app/hubproxy .
18-
COPY --from=builder /app/config.toml .
19-
COPY --from=builder /app/public ./public
20-
21-
CMD ["./hubproxy"]
1+
FROM golang:1.24-alpine AS builder
2+
3+
WORKDIR /app
4+
COPY src/go.mod src/go.sum ./
5+
RUN go mod download
6+
7+
COPY src/ .
8+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -trimpath -o hubproxy .
9+
10+
FROM alpine
11+
12+
WORKDIR /root/
13+
14+
# 安装skopeo
15+
RUN apk add --no-cache skopeo && mkdir -p temp && chmod 700 temp
16+
17+
COPY --from=builder /app/hubproxy .
18+
COPY --from=builder /app/src/config.toml .
19+
COPY --from=builder /app/src/public ./public
20+
21+
CMD ["./hubproxy"]

README.md

Lines changed: 60 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,95 @@
1-
### Docker和Github加速二合一
2-
3-
- 使用`docker`一键部署多种仓库的镜像加速
4-
- `docker`镜像默认缓存3天
5-
- 支持在线下载`docker`离线镜像包
6-
- 支持镜像搜索
7-
- 具有自动清理机制
8-
- 支持`github`文件加速
9-
- 支持`api.github.com`
10-
- 支持shell脚本嵌套加速
11-
- 支持Al模型库Hugging Face
12-
- 支持IP限流,默认每个IP,每小时20次请求。
13-
- 轻量级,简单方便
14-
- 自动配置HTTPS,默认使用caddy反代,请确保80和443端口没被占用
1+
# HubProxy
152

16-
---
3+
🚀 **Docker 和 GitHub 加速代理服务器**
174

18-
### 使用Docker部署
5+
一个轻量级、高性能的多功能代理服务,提供 Docker 镜像加速、GitHub 文件加速等功能。
196

20-
1:域名解析:将`hub``ghcr``docker`这个几个解析为你的二级域名。
7+
## ✨ 特性
218

22-
> 嫌麻烦也可以直接泛解析
9+
- 🐳 **Docker 镜像加速** - 支持 Docker Hub、GHCR、Quay 等多个镜像仓库,以及优化拉取速度。支持批量下载离线镜像包。
10+
- 📁 **GitHub 文件加速** - 加速 GitHub Release、Raw 文件下载,脚本嵌套加速,以及api.github。com
11+
- 🤖 **AI 模型库支持** - 支持 Hugging Face 模型下载加速
12+
- 🛡️ **智能限流** - IP 限流保护,防止滥用
13+
- 🔍 **镜像搜索** - 在线搜索 Docker 镜像
14+
-**轻量高效** - 基于 Go 语言,单二进制文件运行,资源占用低
15+
- 🔧 **配置热重载** - 统一配置管理,部分配置项支持热重载,无需重启服务
2316

17+
## 🚀 快速开始
2418

25-
2:拉取本项目
19+
### Docker部署(推荐)
2620
```
27-
git clone https://github.com/sky22333/hubproxy.git
21+
docker run -d \
22+
--name hubproxy \
23+
-p 5000:5000 \
24+
--restart always \
25+
ghcr.io/sky22333/hubproxy
2826
```
2927

3028

31-
3:其他无需修改,只需修改`docker-compose.yml`配置里的域名环境变量,修改为你的`根域名`
3229

33-
> 这里的`根域名`只是为了动态写入配置和前端,不用解析,当然也不会影响你的根域名使用。
30+
### 一键安装
3431

35-
运行:
36-
```
37-
docker compose up -d
32+
```bash
33+
curl -fsSL https://raw.githubusercontent.com/sky22333/hubproxy/main/install-service.sh | sudo bash
3834
```
3935

40-
4:部署完成后稍等一分钟,等待`caddy`自动配置域名证书后,即可访问`hub.example.com`查看前端
36+
这个命令会:
37+
- 🔍 自动检测系统架构(AMD64/ARM64)
38+
- 📥 从 GitHub Releases 下载最新版本
39+
- ⚙️ 自动配置系统服务
40+
- 🔄 保留现有配置(升级时)
4141

42-
> 可以使用命令`docker logs -f caddy`查看日志获取进度
4342

4443

44+
## 📖 使用方法
4545

46-
---
47-
---
48-
---
46+
### Docker 镜像加速
47+
48+
```bash
49+
# 原命令
50+
docker pull nginx
51+
52+
# 使用加速(替换 yourdomain.com)
53+
docker pull yourdomain.com/nginx
4954

50-
#### 单独部署Github文件加速(可选)
55+
# ghcr加速(替换 yourdomain.com)
56+
docker pull yourdomain.com/ghcr.io/user/images
5157
```
52-
docker run -d \
53-
--name ghproxy \
54-
-p 5000:5000 \
55-
--restart always \
56-
ghcr.io/sky22333/hubproxy
58+
59+
### GitHub 文件加速
60+
61+
```bash
62+
# 原链接
63+
https://github.com/user/repo/releases/download/v1.0.0/file.tar.gz
64+
65+
# 加速链接
66+
https://yourdomain.com/https://github.com/user/repo/releases/download/v1.0.0/file.tar.gz
5767
```
5868

59-
---
60-
---
6169

6270

63-
<details>
64-
<summary>CF-CDN获取用户真实IP</summary>
65-
71+
## ⚙️ 配置
6672

67-
- 替换`Caddyfile`配置
73+
主配置文件位于 `/opt/hubproxy/config.toml`
6874

69-
```
70-
hub.{$DOMAIN} {
71-
reverse_proxy * ghproxy:5000 {
72-
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
73-
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
74-
header_up X-Forwarded-Proto {http.request.scheme}
75-
header_up CF-IPCountry {http.request.header.CF-IPCountry}
76-
}
77-
}
78-
79-
docker.{$DOMAIN} {
80-
@v2_manifest_blob path_regexp v2_rewrite ^/v2/([^/]+)/(manifests|blobs)/(.*)$
81-
handle @v2_manifest_blob {
82-
rewrite * /v2/library/{re.v2_rewrite.1}/{re.v2_rewrite.2}/{re.v2_rewrite.3}
83-
}
84-
85-
reverse_proxy * docker:5000 {
86-
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
87-
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
88-
header_up X-Forwarded-Proto {http.request.scheme}
89-
header_up CF-IPCountry {http.request.header.CF-IPCountry}
90-
}
91-
}
92-
93-
ghcr.{$DOMAIN} {
94-
reverse_proxy * ghcr:5000 {
95-
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
96-
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
97-
header_up X-Forwarded-Proto {http.request.scheme}
98-
header_up CF-IPCountry {http.request.header.CF-IPCountry}
99-
}
100-
}
101-
```
10275

103-
</details>
10476

10577

106-
---
107-
---
78+
## 🙏 致谢
10879

109-
#### 鸣谢:
11080

111-
ghproxy基于go语言的Gin框架,镜像加速基于`registry`镜像实现
81+
- UI 界面参考了[相关开源项目](https://github.com/WJQSERVER-STUDIO/GHProxy-Frontend)
11282

113-
前端借鉴了[此项目](https://github.com/WJQSERVER-STUDIO/ghproxy)的UI,许可证见`ghproxy/LICENSE`
83+
## ⚠️ 免责声明
84+
85+
- 本程序仅供学习交流使用,请勿用于非法用途
86+
- 使用本程序需遵守当地法律法规
87+
- 作者不对使用者的任何行为承担责任
88+
89+
---
11490

91+
<div align="center">
11592

116-
### 免责声明
93+
**⭐ 如果这个项目对你有帮助,请给个 Star!⭐**
11794

118-
* 本程序完全开源并且仅供学习了解,请勿下载非法文件,使用本项目即默认接受此条款。
119-
* 使用本程序必循遵守部署免责声明。使用本程序必循遵守部署服务器所在地、所在国家和用户所在国家的法律法规, 程序作者不对使用者任何不当行为负责。
95+
</div>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
services:
2-
ghproxy:
3-
build: .
4-
restart: always
5-
ports:
6-
- '5000:5000'
7-
volumes:
8-
- ./config.toml:/root/config.toml
1+
services:
2+
ghproxy:
3+
build: .
4+
restart: always
5+
ports:
6+
- '5000:5000'
7+
volumes:
8+
- ./src/config.toml:/root/config.toml

0 commit comments

Comments
 (0)