Merge branch 'Wei-Shaw:main' into main

This commit is contained in:
程序猿MT
2025-12-31 14:40:52 +08:00
committed by GitHub
4 changed files with 79 additions and 3 deletions

View File

@@ -98,6 +98,13 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
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
run: |
# 确保获取完整的 annotated tag 信息
@@ -161,6 +168,7 @@ jobs:
VERSION=${TAG_NAME#v}
REPO="${{ github.repository }}"
DOCKER_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/sub2api"
GHCR_IMAGE="ghcr.io/${REPO}"
# 获取 tag message 内容
TAG_MESSAGE='${{ steps.tag_message.outputs.message }}'
@@ -181,12 +189,15 @@ jobs:
MESSAGE+="🐳 *Docker 部署:*"$'\n'
MESSAGE+="\`\`\`bash"$'\n'
MESSAGE+="# Docker Hub"$'\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'
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//./_}"
# 发送消息

View File

@@ -78,6 +78,33 @@ dockers:
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--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:
- name_template: "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}"
@@ -100,6 +127,27 @@ docker_manifests:
- "{{ .Env.DOCKERHUB_USERNAME }}/sub2api:{{ .Version }}-amd64"
- "{{ .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:
github:
owner: "{{ .Env.GITHUB_REPO_OWNER }}"
@@ -119,6 +167,15 @@ release:
## 📥 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):**
```bash
curl -sSL https://raw.githubusercontent.com/{{ .Env.GITHUB_REPO_OWNER }}/{{ .Env.GITHUB_REPO_NAME }}/main/deploy/install.sh | sudo bash

View File

@@ -240,7 +240,7 @@ func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *Acco
func (s *OpenAIGatewayService) shouldFailoverUpstreamError(statusCode int) bool {
switch statusCode {
case 401, 403, 429, 529:
case 401, 402, 403, 429, 529:
return true
default:
return statusCode >= 500
@@ -454,6 +454,10 @@ func (s *OpenAIGatewayService) handleErrorResponse(ctx context.Context, resp *ht
statusCode = http.StatusBadGateway
errType = "upstream_error"
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:
statusCode = http.StatusBadGateway
errType = "upstream_error"

View File

@@ -39,6 +39,10 @@ func (s *RateLimitService) HandleUpstreamError(ctx context.Context, account *Acc
// 认证失败:停止调度,记录错误
s.handleAuthError(ctx, account, "Authentication failed (401): invalid or expired credentials")
return true
case 402:
// 支付要求:余额不足或计费问题,停止调度
s.handleAuthError(ctx, account, "Payment required (402): insufficient balance or billing issue")
return true
case 403:
// 禁止访问:停止调度,记录错误
s.handleAuthError(ctx, account, "Access forbidden (403): account may be suspended or lack permissions")