fix: build

This commit is contained in:
tbphp
2025-06-07 12:30:35 +08:00
parent 63581d0556
commit 3b73f8348f
4 changed files with 65 additions and 15 deletions

View File

@@ -16,6 +16,8 @@ jobs:
permissions: permissions:
contents: read contents: read
packages: write packages: write
id-token: write
attestations: write
steps: steps:
- name: Checkout repository - name: Checkout repository
@@ -44,6 +46,7 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}} type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image - name: Build and push Docker image
id: build
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
@@ -55,7 +58,7 @@ jobs:
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
- name: Generate artifact attestation - name: Generate artifact attestation
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request' && steps.build.outputs.digest != ''
uses: actions/attest-build-provenance@v1 uses: actions/attest-build-provenance@v1
with: with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

View File

@@ -137,18 +137,49 @@ docker-build:
docker tag gpt-load:$(VERSION) gpt-load:latest docker tag gpt-load:$(VERSION) gpt-load:latest
@echo "✅ Docker 镜像构建完成" @echo "✅ Docker 镜像构建完成"
# Docker 运行 # Docker 运行(使用预构建镜像)
.PHONY: docker-run .PHONY: docker-run
docker-run: docker-run:
@echo "🐳 运行 Docker 容器..." @echo "🐳 运行 Docker 容器(预构建镜像)..."
docker run -d \ docker run -d \
--name gpt-load \ --name gpt-load \
-p 3000:3000 \ -p 3000:3000 \
-v $(PWD)/keys.txt:/app/keys.txt:ro \ -v $(PWD)/keys.txt:/app/keys.txt:ro \
-v $(PWD)/.env:/app/.env:ro \ -v $(PWD)/.env:/app/.env:ro \
--restart unless-stopped \ --restart unless-stopped \
ghcr.io/tbphp/gpt-load:latest
# Docker 运行(本地构建)
.PHONY: docker-run-local
docker-run-local:
@echo "🐳 运行 Docker 容器(本地构建)..."
docker run -d \
--name gpt-load-local \
-p 3000:3000 \
-v $(PWD)/keys.txt:/app/keys.txt:ro \
-v $(PWD)/.env:/app/.env:ro \
--restart unless-stopped \
gpt-load:latest gpt-load:latest
# Docker Compose 运行(预构建镜像)
.PHONY: compose-up
compose-up:
@echo "🐳 使用 Docker Compose 启动(预构建镜像)..."
docker-compose up -d
# Docker Compose 运行(本地构建)
.PHONY: compose-up-dev
compose-up-dev:
@echo "🐳 使用 Docker Compose 启动(本地构建)..."
docker-compose -f docker-compose.dev.yml up -d
# Docker Compose 停止
.PHONY: compose-down
compose-down:
@echo "🐳 停止 Docker Compose..."
docker-compose down
docker-compose -f docker-compose.dev.yml down 2>/dev/null || true
# 健康检查 # 健康检查
.PHONY: health .PHONY: health
health: health:
@@ -203,7 +234,11 @@ help:
@echo "" @echo ""
@echo "Docker 相关:" @echo "Docker 相关:"
@echo " docker-build - 构建 Docker 镜像" @echo " docker-build - 构建 Docker 镜像"
@echo " docker-run - 运行 Docker 容器" @echo " docker-run - 运行 Docker 容器(预构建镜像)"
@echo " docker-run-local - 运行 Docker 容器(本地构建)"
@echo " compose-up - Docker Compose 启动(预构建镜像)"
@echo " compose-up-dev - Docker Compose 启动(本地构建)"
@echo " compose-down - Docker Compose 停止"
@echo "" @echo ""
@echo "管理相关:" @echo "管理相关:"
@echo " health - 健康检查" @echo " health - 健康检查"

View File

@@ -1,6 +1,6 @@
# GPT-Load # GPT-Load
![Docker Build](https://github.com/tangbo/gpt-load/actions/workflows/docker-build.yml/badge.svg) ![Docker Build](https://github.com/tbphp/gpt-load/actions/workflows/docker-build.yml/badge.svg)
![Go Version](https://img.shields.io/badge/Go-1.21+-blue.svg) ![Go Version](https://img.shields.io/badge/Go-1.21+-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg)
@@ -61,13 +61,25 @@ make build
```bash ```bash
# 从GitHub Container Registry拉取镜像 # 从GitHub Container Registry拉取镜像
docker pull ghcr.io/tangbo/gpt-load:latest docker pull ghcr.io/tbphp/gpt-load:latest
# 运行容器 # 运行容器
docker run -d -p 3000:3000 \ docker run -d -p 3000:3000 \
-e KEYS_FILE=/app/keys.txt \ -e KEYS_FILE=/app/keys.txt \
-v $(pwd)/keys.txt:/app/keys.txt \ -v $(pwd)/keys.txt:/app/keys.txt \
ghcr.io/tangbo/gpt-load:latest ghcr.io/tbphp/gpt-load:latest
```
#### 使用 Docker Compose推荐
```bash
# 使用预构建镜像启动
make compose-up
# 或者
docker-compose up -d
# 停止服务
make compose-down
``` ```
#### 本地构建镜像 #### 本地构建镜像
@@ -76,11 +88,11 @@ docker run -d -p 3000:3000 \
# 构建镜像 # 构建镜像
make docker-build make docker-build
# 运行容器 # 运行容器(本地构建)
make docker-run make docker-run-local
# 或使用 docker-compose # 或使用 docker-compose(本地构建)
docker-compose up -d make compose-up-dev
``` ```
## ⚙️ 配置管理 ## ⚙️ 配置管理
@@ -128,7 +140,7 @@ cp .env.example .env
```bash ```bash
# 拉取最新镜像 # 拉取最新镜像
docker pull ghcr.io/tangbo/gpt-load:latest docker pull ghcr.io/tbphp/gpt-load:latest
``` ```
详细配置说明请参考:[GitHub Actions 配置指南](.docs/github-actions-setup.md) 详细配置说明请参考:[GitHub Actions 配置指南](.docs/github-actions-setup.md)

View File

@@ -2,7 +2,7 @@ version: "3.8"
services: services:
gpt-load: gpt-load:
build: . image: ghcr.io/tbphp/gpt-load:latest
container_name: gpt-load container_name: gpt-load
ports: ports:
- "3000:3000" - "3000:3000"