DaoCloud / crproxy

CRProxy (Container Registry Proxy) is a generic image proxy
MIT License
378 stars 98 forks source link

Enhance `ParseOriginPathInfo` to Support Image Retrieval Without Hostname [target: docker.io] #11

Closed slayercat closed 5 months ago

slayercat commented 5 months ago

Description

This merge request improves the ParseOriginPathInfo function to allow images to be pulled without specifying a hostname. The hostname used is docker.io.

Examples

Here are some examples demonstrating the functionality:

docker pull 127.0.0.1:8081/busybox
docker pull 127.0.0.1:8081/pytorch/pytorch
docker pull 127.0.0.1:8081/registry.k8s.io/busybox:latest
[root@sc150 crproxy]# http_proxy=socks5://127.0.0.1:12345 https_proxy=socks5://127.0.0.1:12345  ./crproxy  --behind  -a :
8081                                                         
127.0.0.1 - - [19/Jun/2024:13:29:31 +0800] "GET /v2/ HTTP/1.1" 200 2
127.0.0.1 - - [19/Jun/2024:13:29:31 +0800] "HEAD /v2/busybox/manifests/latest HTTP/1.1" 403 86
127.0.0.1 - - [19/Jun/2024:13:29:31 +0800] "GET /v2/busybox/manifests/latest HTTP/1.1" 403 86

[root@sc150 crproxy]# docker pull 127.0.0.1:8081/busybox
Using default tag: latest
Error response from daemon: denied

^C
[root@sc150 crproxy]# http_proxy=socks5://127.0.0.1:12345 https_proxy=socks5://127.0.0.1:12345  ./crproxy  --behind -a :8081
127.0.0.1 - - [17/Jun/2024:20:56:34 +0800] "GET /v2/ HTTP/1.1" 200 2
[cr proxy] 2024/06/17 20:56:34 cache client registry-1.docker.io library/busybox
[cr proxy] 2024/06/17 20:56:35 ping registry-1.docker.io
127.0.0.1 - - [17/Jun/2024:20:56:34 +0800] "HEAD /v2/busybox/manifests/latest HTTP/1.1" 200 0
127.0.0.1 - - [17/Jun/2024:20:56:45 +0800] "GET /v2/ HTTP/1.1" 200 2
[cr proxy] 2024/06/17 20:56:45 cache client registry.k8s.io busybox
[cr proxy] 2024/06/17 20:56:45 redirect [https://registry.k8s.io/v2/busybox/manifests/latest https://asia-east1-docker.pkg.dev/v2/k8s-artifacts-prod/images/busybox/manifests/latest]
127.0.0.1 - - [17/Jun/2024:20:56:45 +0800] "HEAD /v2/registry.k8s.io/busybox/manifests/latest HTTP/1.1" 200 0
[cr proxy] 2024/06/17 20:56:46 redirect [https://registry.k8s.io/v2/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67 https://asia-east1-docker.pkg.dev/v2/k8s-artifacts-prod/images/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67]
127.0.0.1 - - [17/Jun/2024:20:56:46 +0800] "GET /v2/registry.k8s.io/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67 HTTP/1.1" 200 0

[root@sc150 crproxy]# http_proxy=socks5://127.0.0.1:12345 https_proxy=socks5://127.0.0.1:12345  ./crproxy  --behind --default-registry registry.k8s.io  -a :8081  
127.0.0.1 - - [17/Jun/2024:20:57:28 +0800] "GET /v2/ HTTP/1.1" 200 2
[cr proxy] 2024/06/17 20:57:28 cache client registry.k8s.io busybox
[cr proxy] 2024/06/17 20:57:28 redirect [https://registry.k8s.io/v2/busybox/manifests/latest https://asia-east1-docker.pkg.dev/v2/k8s-artifacts-prod/images/busybox/manifests/latest]
127.0.0.1 - - [17/Jun/2024:20:57:28 +0800] "HEAD /v2/busybox/manifests/latest HTTP/1.1" 200 0
[cr proxy] 2024/06/17 20:57:29 redirect [https://registry.k8s.io/v2/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67 https://asia-east1-docker.pkg.dev/v2/k8s-artifacts-prod/images/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67]
127.0.0.1 - - [17/Jun/2024:20:57:28 +0800] "GET /v2/busybox/manifests/sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67 HTTP/1.1" 200 0

Please reach out if you have any questions or need further clarification.