Merge branch 'Wei-Shaw:main' into main
This commit is contained in:
15
.github/workflows/release.yml
vendored
15
.github/workflows/release.yml
vendored
@@ -98,6 +98,13 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Fetch tags with annotations
|
- name: Fetch tags with annotations
|
||||||
run: |
|
run: |
|
||||||
# 确保获取完整的 annotated tag 信息
|
# 确保获取完整的 annotated tag 信息
|
||||||
@@ -161,6 +168,7 @@ jobs:
|
|||||||
VERSION=${TAG_NAME#v}
|
VERSION=${TAG_NAME#v}
|
||||||
REPO="${{ github.repository }}"
|
REPO="${{ github.repository }}"
|
||||||
DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api"
|
DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api"
|
||||||
|
GHCR_IMAGE="ghcr.io/${REPO}"
|
||||||
|
|
||||||
# 获取 tag message 内容
|
# 获取 tag message 内容
|
||||||
TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
|
TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
|
||||||
@@ -181,12 +189,15 @@ jobs:
|
|||||||
|
|
||||||
MESSAGE+="🐳 *Docker 部署:*"$'\n'
|
MESSAGE+="🐳 *Docker 部署:*"$'\n'
|
||||||
MESSAGE+="\`\`\`bash"$'\n'
|
MESSAGE+="\`\`\`bash"$'\n'
|
||||||
|
MESSAGE+="# Docker Hub"$'\n'
|
||||||
MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n'
|
MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n'
|
||||||
MESSAGE+="docker pull ${DOCKER_IMAGE}:latest"$'\n'
|
MESSAGE+="# GitHub Container Registry"$'\n'
|
||||||
|
MESSAGE+="docker pull ${GHCR_IMAGE}:${TAG_NAME}"$'\n'
|
||||||
MESSAGE+="\`\`\`"$'\n'$'\n'
|
MESSAGE+="\`\`\`"$'\n'$'\n'
|
||||||
MESSAGE+="🔗 *相关链接:*"$'\n'
|
MESSAGE+="🔗 *相关链接:*"$'\n'
|
||||||
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
|
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
|
||||||
MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'$'\n'
|
MESSAGE+="• [Docker Hub](https://hub.docker.com/r/${DOCKER_IMAGE})"$'\n'
|
||||||
|
MESSAGE+="• [GitHub Packages](https://github.com/${REPO}/pkgs/container/sub2api)"$'\n'$'\n'
|
||||||
MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}"
|
MESSAGE+="#Sub2API #Release #${TAG_NAME//./_}"
|
||||||
|
|
||||||
# 发送消息
|
# 发送消息
|
||||||
|
|||||||
@@ -78,6 +78,33 @@ dockers:
|
|||||||
- "--label=org.opencontainers.image.version={{ .Version }}"
|
- "--label=org.opencontainers.image.version={{ .Version }}"
|
||||||
- "--label=org.opencontainers.image.revision={{ .Commit }}"
|
- "--label=org.opencontainers.image.revision={{ .Commit }}"
|
||||||
|
|
||||||
|
# GHCR images
|
||||||
|
- id: ghcr-amd64
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-amd64"
|
||||||
|
dockerfile: Dockerfile.goreleaser
|
||||||
|
use: buildx
|
||||||
|
build_flag_templates:
|
||||||
|
- "--platform=linux/amd64"
|
||||||
|
- "--label=org.opencontainers.image.version={{ .Version }}"
|
||||||
|
- "--label=org.opencontainers.image.revision={{ .Commit }}"
|
||||||
|
- "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}"
|
||||||
|
|
||||||
|
- id: ghcr-arm64
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
dockerfile: Dockerfile.goreleaser
|
||||||
|
use: buildx
|
||||||
|
build_flag_templates:
|
||||||
|
- "--platform=linux/arm64"
|
||||||
|
- "--label=org.opencontainers.image.version={{ .Version }}"
|
||||||
|
- "--label=org.opencontainers.image.revision={{ .Commit }}"
|
||||||
|
- "--label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}"
|
||||||
|
|
||||||
# Docker manifests for multi-arch support
|
# Docker manifests for multi-arch support
|
||||||
docker_manifests:
|
docker_manifests:
|
||||||
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}"
|
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}"
|
||||||
@@ -100,6 +127,27 @@ docker_manifests:
|
|||||||
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
|
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
|
||||||
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
|
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
|
||||||
|
# GHCR manifests
|
||||||
|
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}"
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-amd64"
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
|
||||||
|
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:latest"
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-amd64"
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
|
||||||
|
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Major }}.{{ .Minor }}"
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-amd64"
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
|
||||||
|
- name_template: "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Major }}"
|
||||||
|
image_templates:
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-amd64"
|
||||||
|
- "ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}-arm64"
|
||||||
|
|
||||||
release:
|
release:
|
||||||
github:
|
github:
|
||||||
owner: "{{ .Env.GITHUB_REPO_OWNER }}"
|
owner: "{{ .Env.GITHUB_REPO_OWNER }}"
|
||||||
@@ -119,6 +167,15 @@ release:
|
|||||||
|
|
||||||
## 📥 Installation
|
## 📥 Installation
|
||||||
|
|
||||||
|
**Docker:**
|
||||||
|
```bash
|
||||||
|
# Docker Hub
|
||||||
|
docker pull {{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}
|
||||||
|
|
||||||
|
# GitHub Container Registry
|
||||||
|
docker pull ghcr.io/{{ .Env.GITHUB_REPO_OWNER }}/sub2api:{{ .Version }}
|
||||||
|
```
|
||||||
|
|
||||||
**One-line install (Linux):**
|
**One-line install (Linux):**
|
||||||
```bash
|
```bash
|
||||||
curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash
|
curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *Acco
|
|||||||
|
|
||||||
func (s *OpenAIGatewayService) shouldFailoverUpstreamError(statusCode int) bool {
|
func (s *OpenAIGatewayService) shouldFailoverUpstreamError(statusCode int) bool {
|
||||||
switch statusCode {
|
switch statusCode {
|
||||||
case 401, 403, 429, 529:
|
case 401, 402, 403, 429, 529:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return statusCode >= 500
|
return statusCode >= 500
|
||||||
@@ -454,6 +454,10 @@ func (s *OpenAIGatewayService) handleErrorResponse(ctx context.Context, resp *ht
|
|||||||
statusCode = http.StatusBadGateway
|
statusCode = http.StatusBadGateway
|
||||||
errType = "upstream_error"
|
errType = "upstream_error"
|
||||||
errMsg = "Upstream authentication failed, please contact administrator"
|
errMsg = "Upstream authentication failed, please contact administrator"
|
||||||
|
case 402:
|
||||||
|
statusCode = http.StatusBadGateway
|
||||||
|
errType = "upstream_error"
|
||||||
|
errMsg = "Upstream payment required: insufficient balance or billing issue"
|
||||||
case 403:
|
case 403:
|
||||||
statusCode = http.StatusBadGateway
|
statusCode = http.StatusBadGateway
|
||||||
errType = "upstream_error"
|
errType = "upstream_error"
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ func (s *RateLimitService) HandleUpstreamError(ctx context.Context, account *Acc
|
|||||||
// 认证失败:停止调度,记录错误
|
// 认证失败:停止调度,记录错误
|
||||||
s.handleAuthError(ctx, account, "Authentication failed (401): invalid or expired credentials")
|
s.handleAuthError(ctx, account, "Authentication failed (401): invalid or expired credentials")
|
||||||
return true
|
return true
|
||||||
|
case 402:
|
||||||
|
// 支付要求:余额不足或计费问题,停止调度
|
||||||
|
s.handleAuthError(ctx, account, "Payment required (402): insufficient balance or billing issue")
|
||||||
|
return true
|
||||||
case 403:
|
case 403:
|
||||||
// 禁止访问:停止调度,记录错误
|
// 禁止访问:停止调度,记录错误
|
||||||
s.handleAuthError(ctx, account, "Access forbidden (403): account may be suspended or lack permissions")
|
s.handleAuthError(ctx, account, "Access forbidden (403): account may be suspended or lack permissions")
|
||||||
|
|||||||
Reference in New Issue
Block a user