feat: github action
This commit is contained in:
63
.github/workflows/docker-build.yml
vendored
Normal file
63
.github/workflows/docker-build.yml
vendored
Normal 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
|
@@ -18,8 +18,10 @@ RUN go mod download
|
||||
# 复制源代码
|
||||
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" \
|
||||
-o gpt-load \
|
||||
./cmd/main.go
|
||||
|
37
README.md
37
README.md
@@ -1,5 +1,9 @@
|
||||
# GPT-Load
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
一个**极致高性能**的 OpenAI API 多密钥轮询透明代理服务器,使用 Go 语言开发!
|
||||
|
||||
## ✨ 特性
|
||||
@@ -53,6 +57,21 @@ make build
|
||||
|
||||
### 方式三: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
|
||||
# 构建镜像
|
||||
make docker-build
|
||||
@@ -96,6 +115,24 @@ cp .env.example .env
|
||||
| `/blacklist` | 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)
|
||||
|
||||
## 🔧 开发指南
|
||||
|
||||
### 可用命令
|
||||
|
Reference in New Issue
Block a user