From efd3d9f9ca85a53dc543a433b4ce4519bc712ffd Mon Sep 17 00:00:00 2001 From: lixd Date: Fri, 14 Jun 2024 09:03:06 +0800 Subject: [PATCH 1/9] modify --- .gitignore | 3 +- README.md | 6 +++ src/help.html | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.js | 27 +++++++--- wrangler.toml | 16 +++--- 5 files changed, 176 insertions(+), 17 deletions(-) create mode 100644 src/help.html diff --git a/.gitignore b/.gitignore index 6356189cb..ea8c64012 100644 --- a/.gitignore +++ b/.gitignore @@ -213,4 +213,5 @@ dist # and uncomment the following lines # .pnp.* -# End of https://www.toptal.com/developers/gitignore/api/yarn \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/yarn +.idea \ No newline at end of file diff --git a/README.md b/README.md index 06b4adced..f4983a8e5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# docs +详细教程 --> [基于 Cloudflare Workers 和 cloudflare-docker-proxy 搭建镜像加速服务](https://www.lixueduan.com/posts/docker/12-docker-mirror/) + +--- + # cloudflare-docker-proxy ![deploy](https://github.com/ciiiii/cloudflare-docker-proxy/actions/workflows/deploy.yaml/badge.svg) @@ -7,6 +12,7 @@ > If you're looking for proxy for helm, maybe you can try [cloudflare-helm-proxy](https://github.com/ciiiii/cloudflare-helm-proxy). ## Deploy +[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lixd/cloudflare-docker-proxy) 1. fork this project 2. modify the link of the above button to your fork url diff --git a/src/help.html b/src/help.html new file mode 100644 index 000000000..d88c908e6 --- /dev/null +++ b/src/help.html @@ -0,0 +1,141 @@ + + + + + + 镜像使用说明 + + + + +
+

镜像使用说明

+ + GitHub + +
+
+
+

为了加速 Docker 镜像拉取,你可以使用以下命令设置 registry mirror:

+
sudo tee /etc/docker/daemon.json <<EOF
+{
+    "registry-mirrors": ["https://{{host}}"]
+}
+EOF
+# 配置完后需要重启 Docker 服务
+sudo systemctl restart docker
+
+

使用该代理从不同的镜像仓库拉取镜像,请参考以下命令:

+

+# docker pull nginx:latest
+docker pull docker.{{host}}/library/nginx:latest  # 拉取 Docker 官方镜像
+
+# docker pull quay.io/coreos/etcd:latest
+docker pull quay.{{host}}/coreos/etcd:latest  # 拉取 Quay 镜像
+
+# docker pull gcr.io/google-containers/busybox:latest
+docker pull gcr.{{host}}/google-containers/busybox:latest  # 拉取 GCR 镜像
+
+# docker pull k8s.gcr.io/pause:latest
+docker pull k8s-gcr.{{host}}/pause:latest  # 拉取 k8s.gcr.io 镜像
+
+# docker pull registry.k8s.io/pause:latest
+docker pull k8s.{{host}}/pause:latest  # 拉取 registry.k8s.io 镜像
+
+# docker pull ghcr.io/github/super-linter:latest
+docker pull ghcr.{{host}}/github/super-linter:latest  # 拉取 GitHub 容器镜像
+
+# docker pull docker.cloudsmith.io/public/repo/image:latest
+docker pull cloudsmith.{{host}}/public/repo/image:latest  # 拉取 Cloudsmith 镜像
+
+

为了避免 Worker 用量耗尽,你可以手动 pull 镜像然后 re-tag 之后 push 至本地镜像仓库。

+
+
+ + + + diff --git a/src/index.js b/src/index.js index e61d67dce..8f74b06ed 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +import DOCS from './help.html' + addEventListener("fetch", (event) => { event.passThroughOnException(); event.respondWith(handleRequest(event.request)); @@ -7,16 +9,16 @@ const dockerHub = "https://registry-1.docker.io"; const routes = { // production - "docker.libcuda.so": dockerHub, - "quay.libcuda.so": "https://quay.io", - "gcr.libcuda.so": "https://gcr.io", - "k8s-gcr.libcuda.so": "https://k8s.gcr.io", - "k8s.libcuda.so": "https://registry.k8s.io", - "ghcr.libcuda.so": "https://ghcr.io", - "cloudsmith.libcuda.so": "https://docker.cloudsmith.io", + "docker.lixd.xyz": dockerHub, + "quay.lixd.xyz": "https://quay.io", + "gcr.lixd.xyz": "https://gcr.io", + "k8s-gcr.lixd.xyz": "https://k8s.gcr.io", + "k8s.lixd.xyz": "https://registry.k8s.io", + "ghcr.lixd.xyz": "https://ghcr.io", + "cloudsmith.lixd.xyz": "https://docker.cloudsmith.io", // staging - "docker-staging.libcuda.so": dockerHub, + "docker-staging.lixd.xyz": dockerHub, }; function routeByHosts(host) { @@ -42,6 +44,15 @@ async function handleRequest(request) { } ); } + // return docs + if (url.pathname === "/") { + return new Response(DOCS, { + status: 200, + headers: { + "content-type": "text/html" + } + }); + } const isDockerHub = upstream == dockerHub; const authorization = request.headers.get("Authorization"); if (url.pathname == "/v2/") { diff --git a/wrangler.toml b/wrangler.toml index 17f18f5fb..bba9196f2 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -13,13 +13,13 @@ TARGET_UPSTREAM = "https://registry-1.docker.io" [env.production] name = "cloudflare-docker-proxy" routes = [ - { pattern = "docker.libcuda.so", custom_domain = true }, - { pattern = "quey.libcuda.so", custom_domain = true }, - { pattern = "gcr.libcuda.so", custom_domain = true }, - { pattern = "k8s-gcr.libcuda.so", custom_domain = true }, - { pattern = "k8s.libcuda.so", custom_domain = true }, - { pattern = "ghcr.libcuda.so", custom_domain = true }, - { pattern = "cloudsmith.libcuda.so", custom_domain = true }, + { pattern = "docker.lixd.xyz", custom_domain = true }, + { pattern = "quay.lixd.xyz", custom_domain = true }, + { pattern = "gcr.lixd.xyz", custom_domain = true }, + { pattern = "k8s-gcr.lixd.xyz", custom_domain = true }, + { pattern = "k8s.lixd.xyz", custom_domain = true }, + { pattern = "ghcr.lixd.xyz", custom_domain = true }, + { pattern = "cloudsmith.lixd.xyz", custom_domain = true }, ] [env.production.vars] @@ -28,7 +28,7 @@ TARGET_UPSTREAM = "" [env.staging] name = "cloudflare-docker-proxy-staging" -route = { pattern = "docker-staging.libcuda.so", custom_domain = true } +route = { pattern = "docker-staging.lixd.xyz", custom_domain = true } [env.staging.vars] MODE = "staging" From 05500ab05594ef9379b3c3207c2250f0dd2b5798 Mon Sep 17 00:00:00 2001 From: chentututu <108245463+chentututu@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:56:55 +0800 Subject: [PATCH 2/9] Update index.js --- src/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 8f74b06ed..858cc4010 100644 --- a/src/index.js +++ b/src/index.js @@ -9,16 +9,16 @@ const dockerHub = "https://registry-1.docker.io"; const routes = { // production - "docker.lixd.xyz": dockerHub, - "quay.lixd.xyz": "https://quay.io", - "gcr.lixd.xyz": "https://gcr.io", - "k8s-gcr.lixd.xyz": "https://k8s.gcr.io", - "k8s.lixd.xyz": "https://registry.k8s.io", - "ghcr.lixd.xyz": "https://ghcr.io", - "cloudsmith.lixd.xyz": "https://docker.cloudsmith.io", + "docker.chenshuang.work": dockerHub, + "quay.chenshuang.work": "https://quay.io", + "gcr.chenshuang.work": "https://gcr.io", + "k8s-gcr.chenshuang.work": "https://k8s.gcr.io", + "k8s.chenshuang.work": "https://registry.k8s.io", + "ghcr.chenshuang.work": "https://ghcr.io", + "cloudsmith.chenshuang.work": "https://docker.cloudsmith.io", // staging - "docker-staging.lixd.xyz": dockerHub, + "docker-staging.chenshuang.work": dockerHub, }; function routeByHosts(host) { From d83941040f4867af0c9f1b076a8957e25e2a4b0d Mon Sep 17 00:00:00 2001 From: chentututu <108245463+chentututu@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:57:48 +0800 Subject: [PATCH 3/9] Update wrangler.toml --- wrangler.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wrangler.toml b/wrangler.toml index bba9196f2..e346dcffe 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -13,13 +13,13 @@ TARGET_UPSTREAM = "https://registry-1.docker.io" [env.production] name = "cloudflare-docker-proxy" routes = [ - { pattern = "docker.lixd.xyz", custom_domain = true }, - { pattern = "quay.lixd.xyz", custom_domain = true }, - { pattern = "gcr.lixd.xyz", custom_domain = true }, - { pattern = "k8s-gcr.lixd.xyz", custom_domain = true }, - { pattern = "k8s.lixd.xyz", custom_domain = true }, - { pattern = "ghcr.lixd.xyz", custom_domain = true }, - { pattern = "cloudsmith.lixd.xyz", custom_domain = true }, + { pattern = "docker.chenshuang.work", custom_domain = true }, + { pattern = "quay.chenshuang.work", custom_domain = true }, + { pattern = "gcr.chenshuang.work", custom_domain = true }, + { pattern = "k8s-gcr.chenshuang.work", custom_domain = true }, + { pattern = "k8s.chenshuang.work", custom_domain = true }, + { pattern = "ghcr.chenshuang.work", custom_domain = true }, + { pattern = "cloudsmith.chenshuang.work", custom_domain = true }, ] [env.production.vars] @@ -28,7 +28,7 @@ TARGET_UPSTREAM = "" [env.staging] name = "cloudflare-docker-proxy-staging" -route = { pattern = "docker-staging.lixd.xyz", custom_domain = true } +route = { pattern = "docker-staging.chenshuang.work", custom_domain = true } [env.staging.vars] MODE = "staging" From d5f998a9751e55197c5aa3871161bc4c3a36b6aa Mon Sep 17 00:00:00 2001 From: chentututu <108245463+chentututu@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:59:38 +0800 Subject: [PATCH 4/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4983a8e5..4397fe24b 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ > If you're looking for proxy for helm, maybe you can try [cloudflare-helm-proxy](https://github.com/ciiiii/cloudflare-helm-proxy). ## Deploy -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lixd/cloudflare-docker-proxy) +[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/chentututu/cloudflare-docker-proxy) 1. fork this project 2. modify the link of the above button to your fork url 3. click the button, you will be redirected to the deploy page -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/ciiiii/cloudflare-docker-proxy) +[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/chentututu/cloudflare-docker-proxy) ## Config tutorial From 72505c9f23fd40d49378d3368b012bb122a62f42 Mon Sep 17 00:00:00 2001 From: chentututu <108245463+chentututu@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:14:38 +0800 Subject: [PATCH 5/9] Update help.html --- src/help.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/help.html b/src/help.html index d88c908e6..35e816f81 100644 --- a/src/help.html +++ b/src/help.html @@ -122,9 +122,9 @@

镜像使用说明