Skip to content

Commit 3f209e8

Browse files
committed
modify
1 parent 00b8c83 commit 3f209e8

File tree

5 files changed

+170
-17
lines changed

5 files changed

+170
-17
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,5 @@ dist
213213
# and uncomment the following lines
214214
# .pnp.*
215215

216-
# End of https://www.toptal.com/developers/gitignore/api/yarn
216+
# End of https://www.toptal.com/developers/gitignore/api/yarn
217+
.idea

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
> If you're looking for proxy for helm, maybe you can try [cloudflare-helm-proxy](https://github.com/ciiiii/cloudflare-helm-proxy).
88
99
## Deploy
10+
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lixd/cloudflare-docker-proxy)
1011

1112
1. fork this project
1213
2. modify the link of the above button to your fork url

src/help.html

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>镜像使用说明</title>
7+
<style>
8+
body {
9+
font-family: 'Roboto', sans-serif;
10+
margin: 0;
11+
padding: 0;
12+
background-color: #f4f4f4;
13+
}
14+
.header {
15+
background: linear-gradient(135deg, #667eea, #764ba2);
16+
color: #fff;
17+
padding: 20px 0;
18+
text-align: center;
19+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
20+
position: relative;
21+
}
22+
.github-link {
23+
position: absolute;
24+
top: 10px;
25+
right: 20px;
26+
color: #fff;
27+
text-decoration: none;
28+
}
29+
.github-icon {
30+
width: 24px;
31+
height: 24px;
32+
vertical-align: middle;
33+
}
34+
.container {
35+
max-width: 800px;
36+
margin: 40px auto;
37+
padding: 20px;
38+
background-color: #fff;
39+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
40+
border-radius: 10px;
41+
}
42+
.content {
43+
margin-bottom: 20px;
44+
}
45+
.footer {
46+
text-align: center;
47+
padding: 20px 0;
48+
background-color: #333;
49+
color: #fff;
50+
}
51+
pre {
52+
background-color: #272822;
53+
color: #f8f8f2;
54+
padding: 15px;
55+
border-radius: 5px;
56+
overflow-x: auto;
57+
}
58+
code {
59+
font-family: 'Source Code Pro', monospace;
60+
}
61+
a {
62+
color: #4CAF50;
63+
text-decoration: none;
64+
}
65+
a:hover {
66+
text-decoration: underline;
67+
}
68+
@media (max-width: 600px) {
69+
.container {
70+
margin: 20px;
71+
padding: 15px;
72+
}
73+
.header {
74+
padding: 15px 0;
75+
}
76+
}
77+
</style>
78+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Source+Code+Pro:wght@400;700&display=swap" rel="stylesheet">
79+
</head>
80+
<body>
81+
<div class="header">
82+
<h1>镜像使用说明</h1>
83+
<a href="https://github.com/lixd/cloudflare-docker-proxy" target="_blank" class="github-link">
84+
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" class="github-icon">
85+
</a>
86+
</div>
87+
<div class="container">
88+
<div class="content">
89+
<p>为了加速 Docker 镜像拉取,你可以使用以下命令设置 registry mirror:</p>
90+
<pre><code id="registry-config">sudo tee /etc/docker/daemon.json &lt;&lt;EOF
91+
{
92+
"registry-mirrors": ["https://{{host}}"]
93+
}
94+
EOF
95+
# 配置完后需要重启 Docker 服务
96+
sudo systemctl restart docker
97+
</code></pre>
98+
<p>使用该代理从不同的镜像仓库拉取镜像,请参考以下命令:</p>
99+
<pre><code id="commands">
100+
# docker pull nginx:latest
101+
docker pull docker.{{host}}/library/nginx:latest # 拉取 Docker 官方镜像
102+
103+
# docker pull quay.io/coreos/etcd:latest
104+
docker pull quay.{{host}}/coreos/etcd:latest # 拉取 Quay 镜像
105+
106+
# docker pull gcr.io/google-containers/busybox:latest
107+
docker pull gcr.{{host}}/google-containers/busybox:latest # 拉取 GCR 镜像
108+
109+
# docker pull k8s.gcr.io/pause:latest
110+
docker pull k8s-gcr.{{host}}/pause:latest # 拉取 k8s.gcr.io 镜像
111+
112+
# docker pull registry.k8s.io/pause:latest
113+
docker pull k8s.{{host}}/pause:latest # 拉取 registry.k8s.io 镜像
114+
115+
# docker pull ghcr.io/github/super-linter:latest
116+
docker pull ghcr.{{host}}/github/super-linter:latest # 拉取 GitHub 容器镜像
117+
118+
# docker pull docker.cloudsmith.io/public/repo/image:latest
119+
docker pull cloudsmith.{{host}}/public/repo/image:latest # 拉取 Cloudsmith 镜像
120+
</code></pre>
121+
<p>为了避免 Worker 用量耗尽,你可以手动 pull 镜像然后 re-tag 之后 push 至本地镜像仓库。</p>
122+
</div>
123+
</div>
124+
<div class="footer">
125+
<p>Powered by Cloudflare Workers</p>
126+
<p><a href="https://lixueduan.com" target="_blank">访问博客 探索云原生</a></p>
127+
</div>
128+
<script>
129+
document.addEventListener('DOMContentLoaded', function() {
130+
const host = window.location.hostname;
131+
const mainDomain = host.split('.').slice(-2).join('.');
132+
const registryConfigElement = document.getElementById('registry-config');
133+
const commandsElement = document.getElementById('commands');
134+
135+
registryConfigElement.innerHTML = registryConfigElement.innerHTML.replace(/{{host}}/g, host);
136+
commandsElement.innerHTML = commandsElement.innerHTML.replace(/{{host}}/g, mainDomain);
137+
});
138+
</script>
139+
</body>
140+
</html>

src/index.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import DOCS from './help.html'
2+
13
addEventListener("fetch", (event) => {
24
event.passThroughOnException();
35
event.respondWith(handleRequest(event.request));
@@ -7,16 +9,16 @@ const dockerHub = "https://registry-1.docker.io";
79

810
const routes = {
911
// production
10-
"docker.libcuda.so": dockerHub,
11-
"quay.libcuda.so": "https://quay.io",
12-
"gcr.libcuda.so": "https://gcr.io",
13-
"k8s-gcr.libcuda.so": "https://k8s.gcr.io",
14-
"k8s.libcuda.so": "https://registry.k8s.io",
15-
"ghcr.libcuda.so": "https://ghcr.io",
16-
"cloudsmith.libcuda.so": "https://docker.cloudsmith.io",
12+
"docker.lixd.xyz": dockerHub,
13+
"quay.lixd.xyz": "https://quay.io",
14+
"gcr.lixd.xyz": "https://gcr.io",
15+
"k8s-gcr.lixd.xyz": "https://k8s.gcr.io",
16+
"k8s.lixd.xyz": "https://registry.k8s.io",
17+
"ghcr.lixd.xyz": "https://ghcr.io",
18+
"cloudsmith.lixd.xyz": "https://docker.cloudsmith.io",
1719

1820
// staging
19-
"docker-staging.libcuda.so": dockerHub,
21+
"docker-staging.lixd.xyz": dockerHub,
2022
};
2123

2224
function routeByHosts(host) {
@@ -42,6 +44,15 @@ async function handleRequest(request) {
4244
}
4345
);
4446
}
47+
// return docs
48+
if (url.pathname === "/") {
49+
return new Response(DOCS, {
50+
status: 200,
51+
headers: {
52+
"content-type": "text/html"
53+
}
54+
});
55+
}
4556
const isDockerHub = upstream == dockerHub;
4657
const authorization = request.headers.get("Authorization");
4758
if (url.pathname == "/v2/") {

wrangler.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ TARGET_UPSTREAM = "https://registry-1.docker.io"
1313
[env.production]
1414
name = "cloudflare-docker-proxy"
1515
routes = [
16-
{ pattern = "docker.libcuda.so", custom_domain = true },
17-
{ pattern = "quey.libcuda.so", custom_domain = true },
18-
{ pattern = "gcr.libcuda.so", custom_domain = true },
19-
{ pattern = "k8s-gcr.libcuda.so", custom_domain = true },
20-
{ pattern = "k8s.libcuda.so", custom_domain = true },
21-
{ pattern = "ghcr.libcuda.so", custom_domain = true },
22-
{ pattern = "cloudsmith.libcuda.so", custom_domain = true },
16+
{ pattern = "docker.lixd.xyz", custom_domain = true },
17+
{ pattern = "quay.lixd.xyz", custom_domain = true },
18+
{ pattern = "gcr.lixd.xyz", custom_domain = true },
19+
{ pattern = "k8s-gcr.lixd.xyz", custom_domain = true },
20+
{ pattern = "k8s.lixd.xyz", custom_domain = true },
21+
{ pattern = "ghcr.lixd.xyz", custom_domain = true },
22+
{ pattern = "cloudsmith.lixd.xyz", custom_domain = true },
2323
]
2424

2525
[env.production.vars]
@@ -28,7 +28,7 @@ TARGET_UPSTREAM = ""
2828

2929
[env.staging]
3030
name = "cloudflare-docker-proxy-staging"
31-
route = { pattern = "docker-staging.libcuda.so", custom_domain = true }
31+
route = { pattern = "docker-staging.lixd.xyz", custom_domain = true }
3232

3333
[env.staging.vars]
3434
MODE = "staging"

0 commit comments

Comments
 (0)