From 1bc56391bb2c8eccab93b74a9791b562e2380b14 Mon Sep 17 00:00:00 2001 From: STARRY-S Date: Tue, 8 Oct 2024 11:24:49 +0800 Subject: [PATCH 1/4] Fix containerd unauthorized response header (#63) --- src/index.js | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/index.js b/src/index.js index 97b0885..015ba6b 100644 --- a/src/index.js +++ b/src/index.js @@ -58,24 +58,9 @@ async function handleRequest(request) { redirect: "follow", }); if (resp.status === 401) { - 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, - }); - } else { - return resp; + return responseUnauthorized(url); } + return resp; } // get token if (url.pathname == "/v2/auth") { @@ -122,7 +107,11 @@ async function handleRequest(request) { headers: request.headers, redirect: "follow", }); - return await fetch(newReq); + const resp = await fetch(newReq); + if (resp.status == 401) { + return responseUnauthorized(url); + } + return resp; } function parseAuthenticate(authenticateStr) { @@ -153,3 +142,22 @@ async function fetchToken(wwwAuthenticate, scope, 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, + }); +} From 696009dd6913269c2ecbeb60636d6f76b89c977f Mon Sep 17 00:00:00 2001 From: Yisheng Cai Date: Mon, 7 Oct 2024 21:27:23 -0600 Subject: [PATCH 2/4] Trigger staging deploy with pull_request_target (#24) * Trigger with pull_request_target * Fix event type * Remove conditions --- .github/workflows/stage.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml index db045f6..ad67f46 100644 --- a/.github/workflows/stage.yaml +++ b/.github/workflows/stage.yaml @@ -1,9 +1,7 @@ name: Deploy to Cloudflare Workers(Staging) on: - pull_request: - branches: - - master + pull_request_target: paths-ignore: - '**.md' repository_dispatch: From 24d7c9fc90e6cbf3116f5ae84ce62c70c3d60a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E7=AE=80aw?= <2801819967@qq.com> Date: Tue, 8 Oct 2024 11:30:07 +0800 Subject: [PATCH 3/4] Fix headers variable initialization (#71) --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 015ba6b..207f689 100644 --- a/src/index.js +++ b/src/index.js @@ -136,7 +136,7 @@ async function fetchToken(wwwAuthenticate, scope, authorization) { if (scope) { url.searchParams.set("scope", scope); } - headers = new Headers(); + const headers = new Headers(); if (authorization) { headers.set("Authorization", authorization); } From 703fae4e6324bab4e0abf9ea5068f997c99956fb Mon Sep 17 00:00:00 2001 From: shxyke Date: Tue, 8 Oct 2024 11:31:11 +0800 Subject: [PATCH 4/4] chore: Update deployment configuration for custom domain (#66) --- .github/workflows/deploy.yaml | 4 ++++ .github/workflows/stage.yaml | 4 ++++ src/index.js | 18 +++++++++--------- wrangler.toml | 3 +++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 8473370..21f7d81 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -16,8 +16,12 @@ 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 \ No newline at end of file diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml index ad67f46..1cd233c 100644 --- a/.github/workflows/stage.yaml +++ b/.github/workflows/stage.yaml @@ -14,8 +14,12 @@ 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 \ No newline at end of file diff --git a/src/index.js b/src/index.js index 207f689..785a41a 100644 --- a/src/index.js +++ b/src/index.js @@ -7,17 +7,17 @@ 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", - "ecr.libcuda.so": "https://public.ecr.aws", + ["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", // staging - "docker-staging.libcuda.so": dockerHub, + ["docker-staging." + CUSTOM_DOMAIN]: dockerHub, }; function routeByHosts(host) { diff --git a/wrangler.toml b/wrangler.toml index c3077a0..b245b95 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -6,6 +6,9 @@ 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"