feat: github action

This commit is contained in:
tbphp
2025-06-07 12:11:06 +08:00
parent e8ba441173
commit 63581d0556
3 changed files with 104 additions and 2 deletions

63
.github/workflows/docker-build.yml vendored Normal file
View File

@@ -0,0 +1,63 @@
name: Build and Push to GitHub Container Registry
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true

View File

@@ -18,8 +18,10 @@ RUN go mod download
# 复制源代码 # 复制源代码
COPY . . COPY . .
# 构建应用 # 构建应用 - 支持多平台
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags="-w -s -X main.Version=2.0.0" \ -ldflags="-w -s -X main.Version=2.0.0" \
-o gpt-load \ -o gpt-load \
./cmd/main.go ./cmd/main.go

View File

@@ -1,5 +1,9 @@
# GPT-Load # GPT-Load
![Docker Build](https://github.com/tangbo/gpt-load/actions/workflows/docker-build.yml/badge.svg)
![Go Version](https://img.shields.io/badge/Go-1.21+-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)
一个**极致高性能**的 OpenAI API 多密钥轮询透明代理服务器,使用 Go 语言开发! 一个**极致高性能**的 OpenAI API 多密钥轮询透明代理服务器,使用 Go 语言开发!
## ✨ 特性 ## ✨ 特性
@@ -53,6 +57,21 @@ make build
### 方式三Docker 运行 ### 方式三Docker 运行
#### 使用预构建镜像(推荐)
```bash
# 从GitHub Container Registry拉取镜像
docker pull ghcr.io/tangbo/gpt-load:latest
# 运行容器
docker run -d -p 3000:3000 \
-e KEYS_FILE=/app/keys.txt \
-v $(pwd)/keys.txt:/app/keys.txt \
ghcr.io/tangbo/gpt-load:latest
```
#### 本地构建镜像
```bash ```bash
# 构建镜像 # 构建镜像
make docker-build make docker-build
@@ -96,6 +115,24 @@ cp .env.example .env
| `/blacklist` | GET | 黑名单详情 | | `/blacklist` | GET | 黑名单详情 |
| `/reset-keys` | GET | 重置所有密钥状态 | | `/reset-keys` | GET | 重置所有密钥状态 |
## 🚀 CI/CD 自动部署
项目已配置 GitHub Actions 自动构建和部署:
- **自动触发**:每次 push 到 main 分支时自动构建
- **多平台支持**:同时构建 Linux AMD64 和 ARM64 镜像
- **GitHub 集成**:自动推送到 GitHub Container Registry
- **缓存优化**:使用 GitHub Actions 缓存加速构建
### 预构建镜像
```bash
# 拉取最新镜像
docker pull ghcr.io/tangbo/gpt-load:latest
```
详细配置说明请参考:[GitHub Actions 配置指南](.docs/github-actions-setup.md)
## 🔧 开发指南 ## 🔧 开发指南
### 可用命令 ### 可用命令