add dockerhub action

This commit is contained in:
Darren 2024-10-22 13:21:58 +08:00 committed by GitHub
parent 85dab10819
commit fad7e84666
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 0 deletions

30
.github/workflows/dockerhub_proxy.yml vendored Normal file
View file

@ -0,0 +1,30 @@
name: Build and push to CloudFlare Worker
on:
workflow_dispatch:
jobs:
build:
name: Spellcheck
runs-on: ubuntu-latest
steps:
# The checkout step
- name: Checkout
uses: actions/checkout@v4
- name: Build cloudflare.js for Dockerhub proxy
run: |
cd docker
curl -o https://raw.githubusercontent.com/Websoft9/doc.websoft9.com/refs/heads/main/docs/reference/_include/dockerhub-proxy.md
echo "Insert proxy lists to cloudflare.js"
- name: Deploy to cloudflare
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
preCommands: cd docker
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: update cloudflare.js

27
docker/cloudflare.js Normal file
View file

@ -0,0 +1,27 @@
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
// This data source from: https://raw.githubusercontent.com/Websoft9/doc.websoft9.com/refs/heads/main/docs/reference/_include/dockerhub-proxy.md
const backends = [
'https://docker.rainbond.cc',
'https://docker.1panel.dev',
'https://docker.fxxk.dedyn.io',
'https://a.ussh.net',
'https://docker.zhai.cm'
]
async function handleRequest(request) {
// 随机选择一个后端服务器
const backend = backends[Math.floor(Math.random() * backends.length)]
// 构建新的请求 URL
const url = new URL(request.url)
url.hostname = new URL(backend).hostname
// 转发请求到选定的后端服务器
const modifiedRequest = new Request(url, request)
const response = await fetch(modifiedRequest)
return response
}