Skip to content

Commit 969c997

Browse files
committed
swagger
1 parent ae3d0ea commit 969c997

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ d. 启动方式2: chmod +x run_app_osx.sh && ./run_app_osx.sh
9494
- `Timeout`:请求超时时间,单位为毫秒,默认值为 `30000`(30秒)。
9595
- `MemoryLimit`:内存限制,单位为MB,默认值为 `128`(128MB)。
9696
- `BufferSize`:缓冲区大小,单位为字节,默认值为 `8192`(8KB)。
97+
- `Concurrent`:并发下载数,默认值为 `4`
9798
- `Username`:Docker Hub 用户名,默认值为空,采用登录方式可提升拉取速度。
9899
- `Password`:Docker Hub 密码,默认值为空,采用登录方式可提升拉取速度。
99100

@@ -104,6 +105,7 @@ d. 启动方式2: chmod +x run_app_osx.sh && ./run_app_osx.sh
104105
"Timeout": 30000,
105106
"MemoryLimit": 128,
106107
"BufferSize": 8192,
108+
"Concurrent": 4,
107109
"Username": "",
108110
"Password": ""
109111
}

scripts/docker-upgrade.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,21 @@ fi
5050

5151
# 运行新的容器
5252
echo "启动新的容器 ${CONTAINER_NAME}..."
53+
54+
mkdir -p ./logs
55+
mkdir -p ./cache
56+
mkdir -p ./cache/manifests
57+
mkdir -p ./cache/blobs
58+
59+
# 添加权限修改
60+
chmod -R 777 ./cache
61+
chmod -R 777 ./logs
62+
5363
docker run --name ${CONTAINER_NAME} -d --restart=always \
5464
-p 8080:8080 \
65+
-v ./logs:/app/logs:rw \
66+
-v ./cache:/app/cache:rw \
67+
-v ./appsettings.json:/app/appsettings.json:ro \
5568
-e TZ=Asia/Shanghai \
5669
${IMAGE_NAME}
5770
if [ $? -ne 0 ]; then

src/DockerProxy/AppConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
/// </summary>
66
public class AppConfig
77
{
8+
/// <summary>
9+
/// 演示环境
10+
/// </summary>
11+
public bool IsDemo { get; set; } = false;
12+
813
/// <summary>
914
/// 缓存目录
1015
/// </summary>
@@ -30,6 +35,11 @@ public class AppConfig
3035
/// </summary>
3136
public int BufferSize { get; set; } = 8192; // 8 KB
3237

38+
/// <summary>
39+
/// 并发下载数量
40+
/// </summary>
41+
public int Concurrent { get; set; } = 4;
42+
3343
/// <summary>
3444
/// Optional credentials for Docker Hub (for higher rate limits)
3545
/// </summary>

src/DockerProxy/Controllers/RegistryController.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace DockerProxy.Controllers
88
{
99
/// <summary>
10+
/// Docker Registry API v2
1011
/// https://docker-docs.uclv.cu/registry/spec/api/
1112
/// </summary>
1213
[ApiController]
@@ -20,13 +21,21 @@ public class RegistryController : ControllerBase
2021
private readonly TokenService _tokenService;
2122
private readonly IHttpClientFactory _httpClientFactory;
2223

23-
public RegistryController(TokenService tokenService, IHttpClientFactory httpClientFactory,
24-
DockerRegistryService registryService, IOptions<AppConfig> config)
24+
public RegistryController(
25+
TokenService tokenService,
26+
IHttpClientFactory httpClientFactory,
27+
DockerRegistryService registryService,
28+
IOptions<AppConfig> config)
2529
{
2630
_tokenService = tokenService;
2731
_httpClientFactory = httpClientFactory;
2832
_registryService = registryService;
2933
_config = config.Value;
34+
35+
var ip = Request.GetIP();
36+
var url = Request.GetUrl();
37+
38+
Log.Information("Received request: {Method} {Url} from {IP}", Request.Method, url, ip);
3039
}
3140

3241
/// <summary>
@@ -43,7 +52,7 @@ public IActionResult GetStatus()
4352
var status = new
4453
{
4554
status = "ok",
46-
version = "1.2.4",
55+
version = "1.3.0",
4756
timestamp = DateTime.UtcNow,
4857
uptime = (int)(DateTime.UtcNow - _startTime).TotalSeconds + " s",
4958
memoryLimit = $"{_config.MemoryLimit} MB",
@@ -74,6 +83,7 @@ public IActionResult HandleV2Root()
7483
[HttpGet("v2/{name}/tags/list")]
7584
public async Task<IActionResult> ListTags(string name)
7685
{
86+
var ip = Request.GetIP();
7787
Log.Information("Listing tags for repository: {Repository}", name);
7888

7989
// Format repository name
@@ -145,8 +155,6 @@ public async Task<IActionResult> HandleV2Request(string path)
145155
var url = Request.GetUrl();
146156
var ip = Request.GetIP();
147157

148-
Log.Information("Received request: {Method} {Url} from {IP}", Request.Method, url, ip);
149-
150158
// Handle manifest requests
151159
var manifestMatch = Regex.Match(path, @"^([^/]+(?:/[^/]+)?)/manifests/(.+)$");
152160
if (manifestMatch.Success)

src/DockerProxy/DockerRegistryMirror.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public DockerRegistryService(TokenService tokenService, IHttpClientFactory httpC
1919
_tokenService = tokenService;
2020
_httpClientFactory = httpClientFactory;
2121
_config = config.Value;
22-
_concurrencySemaphore = new SemaphoreSlim(4, 4); // Allow 4 concurrent requests
22+
23+
// Allow 4 concurrent requests
24+
var core = Math.Max(1, _config.Concurrent);
25+
26+
_concurrencySemaphore = new SemaphoreSlim(core, core);
2327
}
2428

2529
public async Task<RegistryResponse> GetManifestAsync(string repository, string reference)

src/DockerProxy/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void Main(string[] args)
9090
app.UseSerilogRequestLogging();
9191

9292
// Configure the HTTP request pipeline.
93-
if (app.Environment.IsDevelopment())
93+
if (app.Environment.IsDevelopment() || config.IsDemo)
9494
{
9595
app.UseSwagger();
9696
app.UseSwaggerUI();

src/DockerProxy/appsettings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
},
3333
"urls": "http://*:8080",
3434
"Registry": {
35+
"IsDemo": false,
3536
"CacheDir": "./cache",
3637
"CacheTTL": 604800,
3738
"Timeout": 30000,
3839
"MemoryLimit": 128,
3940
"BufferSize": 8192,
41+
"Concurrent": 4,
4042
"Username": "",
4143
"Password": ""
4244
}

0 commit comments

Comments
 (0)