mirror of
https://github.com/NoCLin/LightMirrors
synced 2025-07-27 12:30:31 +08:00
fix
This commit is contained in:
parent
19c63bba60
commit
d63f28ba3a
25
README.md
25
README.md
@ -28,18 +28,11 @@ LightMirrors是一个开源的缓存镜像站服务,用于加速软件包下
|
||||
由于国内访问国外软件源的速度较慢,特别是DockerHub缺少国内镜像站,
|
||||
因此我们在本地部署镜像站来加速网络访问和节省外网带宽。
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- docker + docker-compose.
|
||||
- 一个域名,设置 `*.yourdomain` 的A记录指向您服务器的IP.
|
||||
- `*.local.homeinfra.org` 默认指向 `127.0.0.1`,本地测试可以直接使用。
|
||||
- 代理服务器(如有必要).
|
||||
|
||||
> 如果需要使用HTTPS,可以在外层新增一个HTTP网关(如Caddy),请参考后续章节。
|
||||
|
||||
执行以下命令以启动LightMirrors:
|
||||
执行以下命令试用LightMirrors:
|
||||
|
||||
```bash
|
||||
|
||||
@ -61,6 +54,18 @@ pip3 download -i http://torch.local.homeinfra.org/whl/ torch --trusted-host torc
|
||||
|
||||
### Deployment
|
||||
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- docker + docker-compose.
|
||||
- 一个域名,设置 `*.yourdomain` 的A记录指向您服务器的IP.
|
||||
- `*.local.homeinfra.org` 默认指向 `127.0.0.1`,本地测试可以直接使用。
|
||||
- 代理服务器(如有必要).
|
||||
|
||||
> 如果需要使用HTTPS,可以在外层新增一个HTTP网关(如Caddy),请参考后续章节。
|
||||
> **对于DockerHub镜像,我们强烈建议启用HTTPS**。
|
||||
|
||||
|
||||
修改 `.env` 文件,设置下列参数:
|
||||
|
||||
- `BASE_DOMAIN`: 基础域名,如 `local.homeinfra.org`,可以通过 `*.local.homeinfra.org` 访问镜像站。
|
||||
|
@ -1,5 +1,6 @@
|
||||
import base64
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from typing import Dict
|
||||
@ -11,6 +12,8 @@ from starlette.responses import Response
|
||||
from proxy.direct import direct_proxy
|
||||
from proxy.file_cache import try_file_based_cache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
BASE_URL = "https://registry-1.docker.io"
|
||||
|
||||
|
||||
@ -36,11 +39,11 @@ def try_extract_image_name(path):
|
||||
|
||||
if match:
|
||||
assert len(match.groups()) == 3
|
||||
name, operation, reference = match.groups()
|
||||
name, resource, reference = match.groups()
|
||||
assert re.match(name_regex, name)
|
||||
assert re.match(reference_regex, reference)
|
||||
assert operation in ["manifests", "blobs"]
|
||||
return name, operation, reference
|
||||
assert resource in ["manifests", "blobs", "tags"]
|
||||
return name, resource, reference
|
||||
|
||||
return None, None, None
|
||||
|
||||
@ -84,8 +87,6 @@ def inject_token(name: str, req: Request, httpx_req: httpx.Request):
|
||||
async def post_process(request: Request, response: Response):
|
||||
if response.status_code == 307:
|
||||
location = response.headers["location"]
|
||||
# TODO: logger
|
||||
print("[redirect]", location)
|
||||
return await try_file_based_cache(request, location)
|
||||
|
||||
return response
|
||||
@ -93,7 +94,6 @@ async def post_process(request: Request, response: Response):
|
||||
|
||||
async def docker(request: Request):
|
||||
path = request.url.path
|
||||
print("[request]", request.method, request.url)
|
||||
if not path.startswith("/v2/"):
|
||||
return Response(content="Not Found", status_code=404)
|
||||
|
||||
@ -101,7 +101,7 @@ async def docker(request: Request):
|
||||
return Response(content="OK")
|
||||
# return await direct_proxy(request, BASE_URL + '/v2/')
|
||||
|
||||
name, operation, reference = try_extract_image_name(path)
|
||||
name, resource, reference = try_extract_image_name(path)
|
||||
|
||||
if not name:
|
||||
return Response(content="404 Not Found", status_code=404)
|
||||
@ -110,10 +110,9 @@ async def docker(request: Request):
|
||||
if "/" not in name:
|
||||
name = f"library/{name}"
|
||||
|
||||
target_url = BASE_URL + f"/v2/{name}/{operation}/{reference}"
|
||||
target_url = BASE_URL + f"/v2/{name}/{resource}/{reference}"
|
||||
|
||||
# logger
|
||||
print("[PARSED]", path, name, operation, reference, target_url)
|
||||
logger.info(f"got docker request, {path=} {name=} {resource=} {reference=} {target_url=}")
|
||||
|
||||
return await direct_proxy(
|
||||
request,
|
||||
|
Loading…
x
Reference in New Issue
Block a user