Compare commits
2 Commits
main
...
Rirmach/do
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4053481714 | ||
|
|
58097f865d |
5
.github/demo/deepwiki.svg
vendored
Normal file
5
.github/demo/deepwiki.svg
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="28" role="img" aria-label="DeepWiki">
|
||||||
|
<title>DeepWiki</title>
|
||||||
|
<rect width="90" height="28" rx="4" fill="#0f766e"></rect>
|
||||||
|
<text x="45" y="19" fill="#fff" font-family="Arial, Helvetica, sans-serif" font-size="12" text-anchor="middle">DeepWiki</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 320 B |
BIN
.github/demo/demo1.jpg
vendored
BIN
.github/demo/demo1.jpg
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 66 KiB |
BIN
.github/demo/demo2.jpg
vendored
Normal file
BIN
.github/demo/demo2.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
BIN
.github/demo/demo3.jpg
vendored
Normal file
BIN
.github/demo/demo3.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
13
.github/workflows/docker-ghcr.yml
vendored
13
.github/workflows/docker-ghcr.yml
vendored
@@ -3,9 +3,9 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: '版本号 (例如: v1.0.0)'
|
description: 'Version number'
|
||||||
required: true
|
required: true
|
||||||
default: 'v1.0.0'
|
default: 'latest'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -36,12 +36,7 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Set version from input
|
- name: Set version from input
|
||||||
run: |
|
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||||
VERSION=${{ github.event.inputs.version }}
|
|
||||||
if [[ $VERSION == v* ]]; then
|
|
||||||
VERSION=${VERSION:1}
|
|
||||||
fi
|
|
||||||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Convert repository name to lowercase
|
- name: Convert repository name to lowercase
|
||||||
run: |
|
run: |
|
||||||
@@ -58,4 +53,4 @@ jobs:
|
|||||||
--build-arg VERSION=${{ env.VERSION }} \
|
--build-arg VERSION=${{ env.VERSION }} \
|
||||||
-f Dockerfile .
|
-f Dockerfile .
|
||||||
env:
|
env:
|
||||||
GHCR_PUBLIC: true
|
GHCR_PUBLIC: true # 将镜像设置为公开
|
||||||
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
name: 发布二进制文件
|
name: 发布二进制文件
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch: # 手动触发
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: '版本号 (例如: v1.0.0)'
|
description: '版本号 (例如: v1.0.0)'
|
||||||
@@ -18,7 +18,7 @@ jobs:
|
|||||||
- name: 检出代码
|
- name: 检出代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0 # 获取完整历史,用于生成变更日志
|
||||||
|
|
||||||
- name: 设置Go环境
|
- name: 设置Go环境
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
|
|||||||
40
README.md
40
README.md
@@ -1,6 +1,12 @@
|
|||||||
# HubProxy
|
# HubProxy
|
||||||
|
|
||||||
**Docker 和 GitHub 加速代理服务器**
|
🚀 **Docker 和 GitHub 加速代理服务器**
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://deepwiki.com/sky22333/hubproxy">
|
||||||
|
<img src="./.github/demo/deepwiki.svg" alt="DeepWiki">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
一个轻量级、高性能的多功能代理服务,提供 Docker 镜像加速、GitHub 文件加速、下载离线镜像、在线搜索 Docker 镜像等功能。
|
一个轻量级、高性能的多功能代理服务,提供 Docker 镜像加速、GitHub 文件加速、下载离线镜像、在线搜索 Docker 镜像等功能。
|
||||||
|
|
||||||
@@ -9,7 +15,7 @@
|
|||||||
<img src="https://count.getloli.com/get/@sky22333.hubproxy?theme=rule34" alt="Visitors">
|
<img src="https://count.getloli.com/get/@sky22333.hubproxy?theme=rule34" alt="Visitors">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## 特性
|
## ✨ 特性
|
||||||
|
|
||||||
- 🐳 **Docker 镜像加速** - 支持 Docker Hub、GHCR、Quay 等多个镜像仓库加速,流式传输优化拉取速度。
|
- 🐳 **Docker 镜像加速** - 支持 Docker Hub、GHCR、Quay 等多个镜像仓库加速,流式传输优化拉取速度。
|
||||||
- 🐳 **离线镜像包** - 支持下载离线镜像包,流式传输加防抖设计。
|
- 🐳 **离线镜像包** - 支持下载离线镜像包,流式传输加防抖设计。
|
||||||
@@ -23,13 +29,8 @@
|
|||||||
- 🛡️ **完全自托管** - 避免依赖免费第三方服务的不稳定性,例如`cloudflare`等等。
|
- 🛡️ **完全自托管** - 避免依赖免费第三方服务的不稳定性,例如`cloudflare`等等。
|
||||||
- 🚀 **多服务统一加速** - 单个程序即可统一加速 Docker、GitHub、Hugging Face 等多种服务,简化部署与管理。
|
- 🚀 **多服务统一加速** - 单个程序即可统一加速 Docker、GitHub、Hugging Face 等多种服务,简化部署与管理。
|
||||||
|
|
||||||
## 详细文档
|
|
||||||
|
|
||||||
[中文文档](https://zread.ai/sky22333/hubproxy)
|
## 🚀 快速开始
|
||||||
|
|
||||||
[English](https://deepwiki.com/sky22333/hubproxy)
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
|
|
||||||
### Docker部署(推荐)
|
### Docker部署(推荐)
|
||||||
```
|
```
|
||||||
@@ -40,6 +41,8 @@ docker run -d \
|
|||||||
ghcr.io/sky22333/hubproxy
|
ghcr.io/sky22333/hubproxy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 一键脚本安装
|
### 一键脚本安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -49,12 +52,14 @@ curl -fsSL https://raw.githubusercontent.com/sky22333/hubproxy/main/install.sh |
|
|||||||
支持单个二进制文件直接启动,无需其他配置,内置默认配置,支持所有功能。
|
支持单个二进制文件直接启动,无需其他配置,内置默认配置,支持所有功能。
|
||||||
|
|
||||||
这个脚本会:
|
这个脚本会:
|
||||||
- 自动检测系统架构(AMD64/ARM64)
|
- 🔍 自动检测系统架构(AMD64/ARM64)
|
||||||
- 从 GitHub Releases 下载最新版本
|
- 📥 从 GitHub Releases 下载最新版本
|
||||||
- 自动配置系统服务
|
- ⚙️ 自动配置系统服务
|
||||||
- 保留现有配置(升级时)
|
- 🔄 保留现有配置(升级时)
|
||||||
|
|
||||||
## 使用方法
|
|
||||||
|
|
||||||
|
## 📖 使用方法
|
||||||
|
|
||||||
### Docker 镜像加速
|
### Docker 镜像加速
|
||||||
|
|
||||||
@@ -98,7 +103,7 @@ https://yourdomain.com/https://github.com/user/repo/releases/download/v1.0.0/fil
|
|||||||
git clone https://yourdomain.com/https://github.com/sky22333/hubproxy.git
|
git clone https://yourdomain.com/https://github.com/sky22333/hubproxy.git
|
||||||
```
|
```
|
||||||
|
|
||||||
## 配置
|
## ⚙️ 配置
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>config.toml 配置说明</summary>
|
<summary>config.toml 配置说明</summary>
|
||||||
@@ -244,9 +249,16 @@ example.com {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
## 界面预览
|
## 界面预览
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Star 趋势
|
## Star 趋势
|
||||||
[](https://starchart.cc/sky22333/hubproxy)
|
[](https://starchart.cc/sky22333/hubproxy)
|
||||||
|
|||||||
264
install.sh
264
install.sh
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# HubProxy 一键安装脚本 (Gitea 私人仓库版)
|
# HubProxy 一键安装脚本
|
||||||
|
# 支持自动下载最新版本或使用本地文件安装
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# 颜色定义
|
# 颜色定义
|
||||||
@@ -8,104 +9,205 @@ RED='\033[0;31m'
|
|||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
NC='\033[0m'
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
# 配置信息
|
# 配置
|
||||||
VERSION="v1.2.1"
|
REPO="sky22333/hubproxy"
|
||||||
|
GITHUB_API="https://api.github.com/repos/${REPO}"
|
||||||
|
GITHUB_RELEASES="${GITHUB_API}/releases"
|
||||||
SERVICE_NAME="hubproxy"
|
SERVICE_NAME="hubproxy"
|
||||||
# 按照你的习惯,安装在 /opt,如果你想完全放在 /vol1 下也可以修改此处
|
INSTALL_DIR="/opt/hubproxy"
|
||||||
INSTALL_DIR="/opt/hubproxy"
|
CONFIG_FILE="config.toml"
|
||||||
BINARY_NAME="hubproxy"
|
BINARY_NAME="hubproxy"
|
||||||
|
LOG_DIR="/var/log/hubproxy"
|
||||||
TEMP_DIR="/tmp/hubproxy-install"
|
TEMP_DIR="/tmp/hubproxy-install"
|
||||||
|
|
||||||
echo -e "${BLUE}HubProxy 一键安装脚本 - 来自 Gitea 私人仓库${NC}"
|
echo -e "${BLUE}HubProxy 一键安装脚本${NC}"
|
||||||
echo "================================================="
|
echo "================================================="
|
||||||
|
|
||||||
# 1. 权限检查
|
# 检查是否以root权限运行
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo -e "${RED}此脚本需要 root 权限运行${NC}"
|
echo -e "${RED}此脚本需要root权限运行${NC}"
|
||||||
|
echo "请使用: sudo $0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. 检测系统架构并匹配你的 Gitea 链接
|
# 检测系统架构
|
||||||
arch=$(uname -m)
|
detect_arch() {
|
||||||
case $arch in
|
local arch=$(uname -m)
|
||||||
x86_64)
|
case $arch in
|
||||||
ARCH="amd64"
|
x86_64)
|
||||||
DOWNLOAD_URL="https://git.vps3344521.xyz/3344/hubproxy/releases/download/v1.2.1/hubproxy-v1.2.1-linux-amd64.tar.gz"
|
echo "amd64"
|
||||||
;;
|
;;
|
||||||
aarch64|arm64)
|
aarch64|arm64)
|
||||||
ARCH="arm64"
|
echo "arm64"
|
||||||
DOWNLOAD_URL="https://git.vps3344521.xyz/3344/hubproxy/releases/download/v1.2.1/hubproxy-v1.2.1-linux-arm64.tar.gz"
|
;;
|
||||||
;;
|
*)
|
||||||
*)
|
echo -e "${RED}不支持的架构: $arch${NC}"
|
||||||
echo -e "${RED}不支持的架构: $arch${NC}"
|
exit 1
|
||||||
exit 1
|
;;
|
||||||
;;
|
esac
|
||||||
esac
|
}
|
||||||
|
|
||||||
echo -e "${BLUE}检测到架构: ${ARCH}${NC}"
|
ARCH=$(detect_arch)
|
||||||
echo -e "${BLUE}准备从 Gitea 下载...${NC}"
|
echo -e "${BLUE}检测到架构: linux-${ARCH}${NC}"
|
||||||
|
|
||||||
# 3. 安装必要工具
|
# 检查是否为本地安装模式
|
||||||
for cmd in curl tar; do
|
if [ -f "${BINARY_NAME}" ]; then
|
||||||
if ! command -v $cmd &> /dev/null; then
|
echo -e "${BLUE}发现本地文件,使用本地安装模式${NC}"
|
||||||
echo -e "${YELLOW}正在安装依赖 $cmd...${NC}"
|
LOCAL_INSTALL=true
|
||||||
apt update && apt install -y $cmd
|
else
|
||||||
fi
|
echo -e "${BLUE}本地无文件,使用自动下载模式${NC}"
|
||||||
done
|
LOCAL_INSTALL=false
|
||||||
|
|
||||||
# 4. 执行下载
|
# 检查依赖
|
||||||
rm -rf "${TEMP_DIR}" && mkdir -p "${TEMP_DIR}"
|
missing_deps=()
|
||||||
cd "${TEMP_DIR}"
|
for cmd in curl jq tar; do
|
||||||
|
if ! command -v $cmd &> /dev/null; then
|
||||||
echo -e "${YELLOW}正在下载: ${DOWNLOAD_URL}${NC}"
|
missing_deps+=($cmd)
|
||||||
curl -L -o "hubproxy.tar.gz" "${DOWNLOAD_URL}"
|
fi
|
||||||
|
done
|
||||||
# 5. 解压 (根据你提供的包结构,通常解压后是一个目录或直接是二进制文件)
|
|
||||||
tar -xzf "hubproxy.tar.gz"
|
if [ ${#missing_deps[@]} -gt 0 ]; then
|
||||||
# 进入解压出的目录(如果压缩包里有 hubproxy 文件夹的话)
|
echo -e "${YELLOW}检测到缺少依赖: ${missing_deps[*]}${NC}"
|
||||||
[ -d "hubproxy" ] && cd hubproxy
|
echo -e "${BLUE}正在自动安装依赖...${NC}"
|
||||||
|
|
||||||
# 6. 配置服务环境
|
apt update && apt install -y curl jq
|
||||||
echo -e "${BLUE}配置安装目录: ${INSTALL_DIR}${NC}"
|
if [ $? -ne 0 ]; then
|
||||||
mkdir -p "${INSTALL_DIR}"
|
echo -e "${RED}依赖安装失败${NC}"
|
||||||
cp "${BINARY_NAME}" "${INSTALL_DIR}/"
|
exit 1
|
||||||
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
|
fi
|
||||||
|
|
||||||
# 如果有默认配置文件也一并复制
|
# 重新检查依赖
|
||||||
if [ -f "config.toml" ]; then
|
for cmd in curl jq tar; do
|
||||||
if [ ! -f "${INSTALL_DIR}/config.toml" ]; then
|
if ! command -v $cmd &> /dev/null; then
|
||||||
cp "config.toml" "${INSTALL_DIR}/"
|
echo -e "${RED}依赖安装后仍缺少: $cmd${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "${GREEN}依赖安装成功${NC}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 7. 写入 Systemd 服务
|
# 自动下载功能
|
||||||
echo -e "${BLUE}正在创建 Systemd 服务...${NC}"
|
if [ "$LOCAL_INSTALL" = false ]; then
|
||||||
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
|
echo -e "${BLUE}获取最新版本信息...${NC}"
|
||||||
[Unit]
|
LATEST_RELEASE=$(curl -s "${GITHUB_RELEASES}/latest")
|
||||||
Description=HubProxy Service
|
if [ $? -ne 0 ]; then
|
||||||
After=network.target
|
echo -e "${RED}无法获取版本信息${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
[Service]
|
VERSION=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
|
||||||
Type=simple
|
if [ "$VERSION" = "null" ]; then
|
||||||
WorkingDirectory=${INSTALL_DIR}
|
echo -e "${RED}无法解析版本信息${NC}"
|
||||||
ExecStart=${INSTALL_DIR}/${BINARY_NAME}
|
exit 1
|
||||||
Restart=always
|
fi
|
||||||
RestartSec=5
|
|
||||||
|
|
||||||
[Install]
|
echo -e "${GREEN}最新版本: ${VERSION}${NC}"
|
||||||
WantedBy=multi-user.target
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# 8. 启动服务
|
# 构造下载URL
|
||||||
|
ASSET_NAME="hubproxy-${VERSION}-linux-${ARCH}.tar.gz"
|
||||||
|
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET_NAME}"
|
||||||
|
|
||||||
|
echo -e "${BLUE}下载: ${ASSET_NAME}${NC}"
|
||||||
|
|
||||||
|
# 创建临时目录并下载
|
||||||
|
rm -rf "${TEMP_DIR}"
|
||||||
|
mkdir -p "${TEMP_DIR}"
|
||||||
|
cd "${TEMP_DIR}"
|
||||||
|
|
||||||
|
curl -L -o "${ASSET_NAME}" "${DOWNLOAD_URL}"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "${RED}下载失败${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 解压
|
||||||
|
tar -xzf "${ASSET_NAME}"
|
||||||
|
if [ $? -ne 0 ] || [ ! -d "hubproxy" ]; then
|
||||||
|
echo -e "${RED}解压失败${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd hubproxy
|
||||||
|
echo -e "${GREEN}下载完成${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${YELLOW}开始安装 HubProxy...${NC}"
|
||||||
|
|
||||||
|
# 停止现有服务(如果存在)
|
||||||
|
if systemctl is-active --quiet ${SERVICE_NAME} 2>/dev/null; then
|
||||||
|
echo -e "${YELLOW}停止现有服务...${NC}"
|
||||||
|
systemctl stop ${SERVICE_NAME}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 备份现有配置(如果存在)
|
||||||
|
CONFIG_BACKUP_EXISTS=false
|
||||||
|
if [ -f "${INSTALL_DIR}/${CONFIG_FILE}" ]; then
|
||||||
|
echo -e "${BLUE}备份现有配置...${NC}"
|
||||||
|
cp "${INSTALL_DIR}/${CONFIG_FILE}" "${TEMP_DIR}/config.toml.backup"
|
||||||
|
CONFIG_BACKUP_EXISTS=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 1. 创建目录结构
|
||||||
|
echo -e "${BLUE}创建目录结构${NC}"
|
||||||
|
mkdir -p ${INSTALL_DIR}
|
||||||
|
mkdir -p ${LOG_DIR}
|
||||||
|
chmod 755 ${INSTALL_DIR}
|
||||||
|
chmod 755 ${LOG_DIR}
|
||||||
|
|
||||||
|
# 2. 复制二进制文件
|
||||||
|
echo -e "${BLUE}复制二进制文件${NC}"
|
||||||
|
cp "${BINARY_NAME}" "${INSTALL_DIR}/"
|
||||||
|
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
|
||||||
|
|
||||||
|
# 3. 复制配置文件
|
||||||
|
echo -e "${BLUE}复制配置文件${NC}"
|
||||||
|
if [ -f "${CONFIG_FILE}" ]; then
|
||||||
|
if [ "$CONFIG_BACKUP_EXISTS" = false ]; then
|
||||||
|
cp "${CONFIG_FILE}" "${INSTALL_DIR}/"
|
||||||
|
echo -e "${GREEN}配置文件复制成功${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}保留现有配置文件${NC}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}配置文件不存在,将使用默认配置${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 5. 安装systemd服务文件
|
||||||
|
echo -e "${BLUE}安装systemd服务文件${NC}"
|
||||||
|
cp "${SERVICE_NAME}.service" "/etc/systemd/system/"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable ${SERVICE_NAME}
|
|
||||||
systemctl restart ${SERVICE_NAME}
|
|
||||||
|
|
||||||
# 9. 清理并完成
|
# 6. 恢复配置文件(如果有备份)
|
||||||
rm -rf "${TEMP_DIR}"
|
if [ "$CONFIG_BACKUP_EXISTS" = true ]; then
|
||||||
echo "-------------------------------------------------"
|
echo -e "${BLUE}恢复配置文件...${NC}"
|
||||||
echo -e "${GREEN}HubProxy 安装成功!${NC}"
|
cp "${TEMP_DIR}/config.toml.backup" "${INSTALL_DIR}/${CONFIG_FILE}"
|
||||||
echo -e "安装路径: ${INSTALL_DIR}"
|
fi
|
||||||
echo -e "服务状态: ${BLUE}systemctl status ${SERVICE_NAME}${NC}"
|
|
||||||
|
# 7. 启用并启动服务
|
||||||
|
echo -e "${BLUE}启用并启动服务${NC}"
|
||||||
|
systemctl enable ${SERVICE_NAME}
|
||||||
|
systemctl start ${SERVICE_NAME}
|
||||||
|
|
||||||
|
# 8. 清理临时文件
|
||||||
|
if [ "$LOCAL_INSTALL" = false ]; then
|
||||||
|
echo -e "${BLUE}清理临时文件...${NC}"
|
||||||
|
cd /
|
||||||
|
rm -rf "${TEMP_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 9. 检查服务状态
|
||||||
|
sleep 2
|
||||||
|
if systemctl is-active --quiet ${SERVICE_NAME}; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}HubProxy 安装成功!${NC}"
|
||||||
|
echo -e "${GREEN}默认运行端口: 5000${NC}"
|
||||||
|
echo -e "${GREEN}配置文件路径: ${INSTALL_DIR}/${CONFIG_FILE}${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}服务启动失败${NC}"
|
||||||
|
echo "查看错误日志: sudo journalctl -u ${SERVICE_NAME} -f"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
@@ -46,19 +46,24 @@ blackList = [
|
|||||||
# 无认证: socks5://127.0.0.1:1080
|
# 无认证: socks5://127.0.0.1:1080
|
||||||
# 有认证: socks5://username:password@127.0.0.1:1080
|
# 有认证: socks5://username:password@127.0.0.1:1080
|
||||||
# 留空不使用代理
|
# 留空不使用代理
|
||||||
proxy = ""
|
proxy = ""
|
||||||
|
|
||||||
[download]
|
[download]
|
||||||
# 批量下载离线镜像数量限制
|
# 批量下载离线镜像数量限制
|
||||||
maxImages = 10
|
maxImages = 10
|
||||||
|
|
||||||
|
# Docker Hub 认证信息,留空则匿名拉取
|
||||||
|
[dockerHubAuth]
|
||||||
|
username = "" # e.g., user1
|
||||||
|
token = "" # e.g., dckr_pat_***
|
||||||
|
|
||||||
# Registry映射配置,支持多种镜像仓库上游
|
# Registry映射配置,支持多种镜像仓库上游
|
||||||
[registries]
|
[registries]
|
||||||
|
|
||||||
# GitHub Container Registry
|
# GitHub Container Registry
|
||||||
[registries."ghcr.io"]
|
[registries."ghcr.io"]
|
||||||
upstream = "ghcr.io"
|
upstream = "ghcr.io"
|
||||||
authHost = "ghcr.io/token"
|
authHost = "ghcr.io/token"
|
||||||
authType = "github"
|
authType = "github"
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ type AppConfig struct {
|
|||||||
MaxImages int `toml:"maxImages"`
|
MaxImages int `toml:"maxImages"`
|
||||||
} `toml:"download"`
|
} `toml:"download"`
|
||||||
|
|
||||||
|
DockerHubAuth struct {
|
||||||
|
Username string `toml:"username"`
|
||||||
|
Token string `toml:"token"`
|
||||||
|
} `toml:"dockerHubAuth"`
|
||||||
|
|
||||||
Registries map[string]RegistryMapping `toml:"registries"`
|
Registries map[string]RegistryMapping `toml:"registries"`
|
||||||
|
|
||||||
TokenCache struct {
|
TokenCache struct {
|
||||||
@@ -108,6 +113,13 @@ func DefaultConfig() *AppConfig {
|
|||||||
}{
|
}{
|
||||||
MaxImages: 10,
|
MaxImages: 10,
|
||||||
},
|
},
|
||||||
|
DockerHubAuth: struct {
|
||||||
|
Username string `toml:"username"`
|
||||||
|
Token string `toml:"token"`
|
||||||
|
}{
|
||||||
|
Username: "",
|
||||||
|
Token: "",
|
||||||
|
},
|
||||||
Registries: map[string]RegistryMapping{
|
Registries: map[string]RegistryMapping{
|
||||||
"ghcr.io": {
|
"ghcr.io": {
|
||||||
Upstream: "ghcr.io",
|
Upstream: "ghcr.io",
|
||||||
|
|||||||
@@ -28,16 +28,9 @@ var dockerProxy *DockerProxy
|
|||||||
type RegistryDetector struct{}
|
type RegistryDetector struct{}
|
||||||
|
|
||||||
// detectRegistryDomain 检测Registry域名并返回域名和剩余路径
|
// detectRegistryDomain 检测Registry域名并返回域名和剩余路径
|
||||||
func (rd *RegistryDetector) detectRegistryDomain(c *gin.Context, path string) (string, string) {
|
func (rd *RegistryDetector) detectRegistryDomain(path string) (string, string) {
|
||||||
cfg := config.GetConfig()
|
cfg := config.GetConfig()
|
||||||
|
|
||||||
// 兼容Containerd的ns参数
|
|
||||||
if ns := c.Query("ns"); ns != "" {
|
|
||||||
if mapping, exists := cfg.Registries[ns]; exists && mapping.Enabled {
|
|
||||||
return ns, path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for domain := range cfg.Registries {
|
for domain := range cfg.Registries {
|
||||||
if strings.HasPrefix(path, domain+"/") {
|
if strings.HasPrefix(path, domain+"/") {
|
||||||
remainingPath := strings.TrimPrefix(path, domain+"/")
|
remainingPath := strings.TrimPrefix(path, domain+"/")
|
||||||
@@ -75,10 +68,18 @@ func InitDockerProxy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
options := []remote.Option{
|
options := []remote.Option{
|
||||||
remote.WithAuth(authn.Anonymous),
|
|
||||||
remote.WithUserAgent("hubproxy/go-containerregistry"),
|
remote.WithUserAgent("hubproxy/go-containerregistry"),
|
||||||
remote.WithTransport(utils.GetGlobalHTTPClient().Transport),
|
remote.WithTransport(utils.GetGlobalHTTPClient().Transport),
|
||||||
}
|
}
|
||||||
|
dockerHubAuth := config.GetConfig().DockerHubAuth
|
||||||
|
if dockerHubAuth.Token != "" && dockerHubAuth.Username != "" {
|
||||||
|
options = append(options, remote.WithAuth(&authn.Basic{
|
||||||
|
Username: dockerHubAuth.Username,
|
||||||
|
Password: dockerHubAuth.Token,
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
options = append(options, remote.WithAuth(authn.Anonymous))
|
||||||
|
}
|
||||||
|
|
||||||
dockerProxy = &DockerProxy{
|
dockerProxy = &DockerProxy{
|
||||||
registry: registry,
|
registry: registry,
|
||||||
@@ -106,7 +107,7 @@ func ProxyDockerRegistryGin(c *gin.Context) {
|
|||||||
func handleRegistryRequest(c *gin.Context, path string) {
|
func handleRegistryRequest(c *gin.Context, path string) {
|
||||||
pathWithoutV2 := strings.TrimPrefix(path, "/v2/")
|
pathWithoutV2 := strings.TrimPrefix(path, "/v2/")
|
||||||
|
|
||||||
if registryDomain, remainingPath := registryDetector.detectRegistryDomain(c, pathWithoutV2); registryDomain != "" {
|
if registryDomain, remainingPath := registryDetector.detectRegistryDomain(pathWithoutV2); registryDomain != "" {
|
||||||
if registryDetector.isRegistryEnabled(registryDomain) {
|
if registryDetector.isRegistryEnabled(registryDomain) {
|
||||||
c.Set("target_registry_domain", registryDomain)
|
c.Set("target_registry_domain", registryDomain)
|
||||||
c.Set("target_path", remainingPath)
|
c.Set("target_path", remainingPath)
|
||||||
|
|||||||
@@ -171,9 +171,9 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
|
|||||||
|
|
||||||
processedBody, processedSize, err := utils.ProcessSmart(resp.Body, isGzipCompressed, realHost)
|
processedBody, processedSize, err := utils.ProcessSmart(resp.Body, isGzipCompressed, realHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("脚本处理失败: %v\n", err)
|
fmt.Printf("智能处理失败,回退到直接代理: %v\n", err)
|
||||||
c.String(http.StatusBadGateway, "Script processing failed: %v", err)
|
processedBody = resp.Body
|
||||||
return
|
processedSize = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 智能设置响应头
|
// 智能设置响应头
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func main() {
|
|||||||
fmt.Printf("H2c: 已启用\n")
|
fmt.Printf("H2c: 已启用\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("版本号: v1.2.1\n")
|
fmt.Printf("版本号: v1.1.9\n")
|
||||||
fmt.Printf("项目地址: https://github.com/sky22333/hubproxy\n")
|
fmt.Printf("项目地址: https://github.com/sky22333/hubproxy\n")
|
||||||
|
|
||||||
// 创建HTTP2服务器
|
// 创建HTTP2服务器
|
||||||
|
|||||||
@@ -200,13 +200,6 @@ func (ac *AccessController) checkList(matches, list []string) bool {
|
|||||||
if strings.HasPrefix(fullRepo, item+"/") {
|
if strings.HasPrefix(fullRepo, item+"/") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(item, "*/") {
|
|
||||||
p := item[2:]
|
|
||||||
if p == repoName || (strings.HasSuffix(p, "*") && strings.HasPrefix(repoName, p[:len(p)-1])) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,46 +10,49 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GitHub URL正则表达式
|
// GitHub URL正则表达式
|
||||||
var githubRegex = regexp.MustCompile(`(?:^|[\s'"(=,\[{;|&<>])https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'")]*`)
|
var githubRegex = regexp.MustCompile(`https?://(?:github\.com|raw\.githubusercontent\.com|raw\.github\.com|gist\.githubusercontent\.com|gist\.github\.com|api\.github\.com)[^\s'"]+`)
|
||||||
|
|
||||||
// MaxShellSize 限制最大处理大小为 10MB
|
|
||||||
const MaxShellSize = 10 * 1024 * 1024
|
|
||||||
|
|
||||||
// ProcessSmart Shell脚本智能处理函数
|
// ProcessSmart Shell脚本智能处理函数
|
||||||
func ProcessSmart(input io.Reader, isCompressed bool, host string) (io.Reader, int64, error) {
|
func ProcessSmart(input io.ReadCloser, isCompressed bool, host string) (io.Reader, int64, error) {
|
||||||
|
defer input.Close()
|
||||||
|
|
||||||
content, err := readShellContent(input, isCompressed)
|
content, err := readShellContent(input, isCompressed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, fmt.Errorf("内容读取失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(content) == 0 {
|
if len(content) == 0 {
|
||||||
return strings.NewReader(""), 0, nil
|
return strings.NewReader(""), 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Contains(content, []byte("github.com")) && !bytes.Contains(content, []byte("githubusercontent.com")) {
|
if len(content) > 10*1024*1024 {
|
||||||
return bytes.NewReader(content), int64(len(content)), nil
|
return strings.NewReader(content), int64(len(content)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
processed := processGitHubURLs(string(content), host)
|
if !strings.Contains(content, "github.com") && !strings.Contains(content, "githubusercontent.com") {
|
||||||
|
return strings.NewReader(content), int64(len(content)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
processed := processGitHubURLs(content, host)
|
||||||
|
|
||||||
return strings.NewReader(processed), int64(len(processed)), nil
|
return strings.NewReader(processed), int64(len(processed)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readShellContent(input io.Reader, isCompressed bool) ([]byte, error) {
|
func readShellContent(input io.ReadCloser, isCompressed bool) (string, error) {
|
||||||
var reader io.Reader = input
|
var reader io.Reader = input
|
||||||
|
|
||||||
if isCompressed {
|
if isCompressed {
|
||||||
peek := make([]byte, 2)
|
peek := make([]byte, 2)
|
||||||
n, err := input.Read(peek)
|
n, err := input.Read(peek)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return nil, fmt.Errorf("读取数据失败: %v", err)
|
return "", fmt.Errorf("读取数据失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n >= 2 && peek[0] == 0x1f && peek[1] == 0x8b {
|
if n >= 2 && peek[0] == 0x1f && peek[1] == 0x8b {
|
||||||
combinedReader := io.MultiReader(bytes.NewReader(peek[:n]), input)
|
combinedReader := io.MultiReader(bytes.NewReader(peek[:n]), input)
|
||||||
gzReader, err := gzip.NewReader(combinedReader)
|
gzReader, err := gzip.NewReader(combinedReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("gzip解压失败: %v", err)
|
return "", fmt.Errorf("gzip解压失败: %v", err)
|
||||||
}
|
}
|
||||||
defer gzReader.Close()
|
defer gzReader.Close()
|
||||||
reader = gzReader
|
reader = gzReader
|
||||||
@@ -58,50 +61,37 @@ func readShellContent(input io.Reader, isCompressed bool) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
limit := int64(MaxShellSize + 1)
|
data, err := io.ReadAll(reader)
|
||||||
limitedReader := io.LimitReader(reader, limit)
|
|
||||||
|
|
||||||
data, err := io.ReadAll(limitedReader)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("读取内容失败: %v", err)
|
return "", fmt.Errorf("读取内容失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if int64(len(data)) > MaxShellSize {
|
return string(data), nil
|
||||||
return nil, fmt.Errorf("脚本文件过大,超过 %d MB 限制", MaxShellSize/1024/1024)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGitHubURLs(content, host string) string {
|
func processGitHubURLs(content, host string) string {
|
||||||
return githubRegex.ReplaceAllStringFunc(content, func(match string) string {
|
return githubRegex.ReplaceAllStringFunc(content, func(url string) string {
|
||||||
// 如果匹配包含前缀分隔符,保留它,防止出现重复转换
|
return transformURL(url, host)
|
||||||
if len(match) > 0 && match[0] != 'h' {
|
|
||||||
prefix := match[0:1]
|
|
||||||
url := match[1:]
|
|
||||||
return prefix + transformURL(url, host)
|
|
||||||
}
|
|
||||||
return transformURL(match, host)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// transformURL URL转换函数
|
// transformURL URL转换函数
|
||||||
func transformURL(url, host string) string {
|
func transformURL(url, host string) string {
|
||||||
if strings.Contains(url, host) {
|
if strings.Contains(url, host) {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, "http://") {
|
if strings.HasPrefix(url, "http://") {
|
||||||
url = "https" + url[4:]
|
url = "https" + url[4:]
|
||||||
} else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") {
|
} else if !strings.HasPrefix(url, "https://") && !strings.HasPrefix(url, "//") {
|
||||||
url = "https://" + url
|
url = "https://" + url
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保 host 有协议头
|
// 确保 host 有协议头
|
||||||
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
|
if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") {
|
||||||
host = "https://" + host
|
host = "https://" + host
|
||||||
}
|
}
|
||||||
host = strings.TrimSuffix(host, "/")
|
host = strings.TrimSuffix(host, "/")
|
||||||
|
|
||||||
return host + "/" + url
|
return host + "/" + url
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user