mirror of
https://github.com/ciiiii/cloudflare-docker-proxy.git
synced 2025-12-06 14:42:51 +08:00
Compare commits
2 Commits
yscai/fix-
...
yscai/regi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1b48aa7d9 | ||
|
|
861a6a8bb1 |
4
.github/workflows/deploy.yaml
vendored
4
.github/workflows/deploy.yaml
vendored
@@ -16,12 +16,8 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
env:
|
||||
CUSTOM_DOMAIN: ${{ secrets.CUSTOM_DOMAIN || 'libcuda.so' }}
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{secrets.CF_ACCOUNT_ID}}
|
||||
vars:
|
||||
CUSTOM_DOMAIN
|
||||
command: deploy --env production --minify src/index.js
|
||||
environment: production
|
||||
8
.github/workflows/stage.yaml
vendored
8
.github/workflows/stage.yaml
vendored
@@ -1,7 +1,9 @@
|
||||
name: Deploy to Cloudflare Workers(Staging)
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
repository_dispatch:
|
||||
@@ -14,12 +16,8 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Publish
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
env:
|
||||
CUSTOM_DOMAIN: ${{ secrets.CUSTOM_DOMAIN || 'libcuda.so' }}
|
||||
with:
|
||||
apiToken: ${{ secrets.CF_API_TOKEN }}
|
||||
accountId: ${{secrets.CF_ACCOUNT_ID}}
|
||||
vars:
|
||||
CUSTOM_DOMAIN
|
||||
command: deploy --env staging --minify src/index.js
|
||||
environment: staging
|
||||
@@ -8,13 +8,13 @@
|
||||
|
||||
## Deploy
|
||||
|
||||
1. click the "Deploy With Workers" button
|
||||
2. follow the instructions to fork and deploy
|
||||
3. update routes as you requirement
|
||||
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
|
||||
|
||||
[](https://deploy.workers.cloudflare.com/?url=https://github.com/ciiiii/cloudflare-docker-proxy)
|
||||
|
||||
## Routes configuration tutorial
|
||||
## Config tutorial
|
||||
|
||||
1. use cloudflare worker host: only support proxy one registry
|
||||
```javascript
|
||||
|
||||
66
src/index.js
66
src/index.js
@@ -7,17 +7,16 @@ const dockerHub = "https://registry-1.docker.io";
|
||||
|
||||
const routes = {
|
||||
// production
|
||||
["docker." + CUSTOM_DOMAIN]: dockerHub,
|
||||
["quay." + CUSTOM_DOMAIN]: "https://quay.io",
|
||||
["gcr." + CUSTOM_DOMAIN]: "https://gcr.io",
|
||||
["k8s-gcr." + CUSTOM_DOMAIN]: "https://k8s.gcr.io",
|
||||
["k8s." + CUSTOM_DOMAIN]: "https://registry.k8s.io",
|
||||
["ghcr." + CUSTOM_DOMAIN]: "https://ghcr.io",
|
||||
["cloudsmith." + CUSTOM_DOMAIN]: "https://docker.cloudsmith.io",
|
||||
["ecr." + CUSTOM_DOMAIN]: "https://public.ecr.aws",
|
||||
"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",
|
||||
|
||||
// staging
|
||||
["docker-staging." + CUSTOM_DOMAIN]: dockerHub,
|
||||
"docker-staging.libcuda.so": dockerHub,
|
||||
};
|
||||
|
||||
function routeByHosts(host) {
|
||||
@@ -58,9 +57,25 @@ async function handleRequest(request) {
|
||||
redirect: "follow",
|
||||
});
|
||||
if (resp.status === 401) {
|
||||
return responseUnauthorized(url);
|
||||
if (MODE == "debug") {
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="http://${url.host}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
} else {
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="https://${url.hostname}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
}
|
||||
headers.set("Docker-Distribution-API-Version", "registry/2.0");
|
||||
return new Response(JSON.stringify({ message: "UNAUTHORIZED" }), {
|
||||
status: 401,
|
||||
headers: headers,
|
||||
});
|
||||
} else {
|
||||
return resp;
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
// get token
|
||||
if (url.pathname == "/v2/auth") {
|
||||
@@ -105,13 +120,9 @@ async function handleRequest(request) {
|
||||
const newReq = new Request(newUrl, {
|
||||
method: request.method,
|
||||
headers: request.headers,
|
||||
redirect: "manual",
|
||||
redirect: "follow",
|
||||
});
|
||||
const resp = await fetch(newReq);
|
||||
if (resp.status == 401) {
|
||||
return responseUnauthorized(url);
|
||||
}
|
||||
return resp;
|
||||
return await fetch(newReq);
|
||||
}
|
||||
|
||||
function parseAuthenticate(authenticateStr) {
|
||||
@@ -136,28 +147,9 @@ async function fetchToken(wwwAuthenticate, scope, authorization) {
|
||||
if (scope) {
|
||||
url.searchParams.set("scope", scope);
|
||||
}
|
||||
const headers = new Headers();
|
||||
headers = new Headers();
|
||||
if (authorization) {
|
||||
headers.set("Authorization", authorization);
|
||||
}
|
||||
return await fetch(url, { method: "GET", headers: headers });
|
||||
}
|
||||
|
||||
function responseUnauthorized(url) {
|
||||
const headers = new(Headers);
|
||||
if (MODE == "debug") {
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="http://${url.host}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
} else {
|
||||
headers.set(
|
||||
"Www-Authenticate",
|
||||
`Bearer realm="https://${url.hostname}/v2/auth",service="cloudflare-docker-proxy"`
|
||||
);
|
||||
}
|
||||
return new Response(JSON.stringify({ message: "UNAUTHORIZED" }), {
|
||||
status: 401,
|
||||
headers: headers,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,25 +6,21 @@ ip = "0.0.0.0"
|
||||
port = 8787
|
||||
local_protocol = "http"
|
||||
|
||||
[env.vars]
|
||||
CUSTOM_DOMAIN = "libcuda.so"
|
||||
|
||||
[env.dev.vars]
|
||||
MODE = "debug"
|
||||
TARGET_UPSTREAM = "https://registry-1.docker.io"
|
||||
CUSTOM_DOMAIN = "exmaple.com"
|
||||
|
||||
[env.production]
|
||||
name = "cloudflare-docker-proxy"
|
||||
# routes = [
|
||||
# { pattern = "docker.libcuda.so", custom_domain = true },
|
||||
# { pattern = "quay.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 },
|
||||
# ]
|
||||
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 },
|
||||
]
|
||||
|
||||
[env.production.vars]
|
||||
MODE = "production"
|
||||
@@ -32,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.libcuda.so", custom_domain = true }
|
||||
|
||||
[env.staging.vars]
|
||||
MODE = "staging"
|
||||
|
||||
Reference in New Issue
Block a user