mirror of
https://github.com/7836246/cursor2api.git
synced 2026-05-20 01:19:02 +08:00
feat: 添加 Docker 支持
- Dockerfile: 基于 Alpine,包含 Chromium 和中文字体 - docker-compose.yml: 配置 shm_size 和安全设置 - .dockerignore: 优化构建上下文 - README.md: 添加 Docker 部署说明
This commit is contained in:
24
.dockerignore
Normal file
24
.dockerignore
Normal file
@@ -0,0 +1,24 @@
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# IDE
|
||||
.idea
|
||||
.vscode
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Build artifacts
|
||||
cursor2api
|
||||
*.exe
|
||||
|
||||
# Docs
|
||||
*.md
|
||||
!README.md
|
||||
|
||||
# Scripts (not needed in container)
|
||||
scripts/
|
||||
|
||||
# Temporary files
|
||||
tmp/
|
||||
*.log
|
||||
53
Dockerfile
Normal file
53
Dockerfile
Normal file
@@ -0,0 +1,53 @@
|
||||
# 构建阶段
|
||||
FROM golang:1.21-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装构建依赖
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# 复制依赖文件
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# 复制源代码
|
||||
COPY . .
|
||||
|
||||
# 构建
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o cursor2api ./cmd/server
|
||||
|
||||
# 运行阶段
|
||||
FROM alpine:3.19
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装 Chromium 和必要的依赖
|
||||
RUN apk add --no-cache \
|
||||
chromium \
|
||||
nss \
|
||||
freetype \
|
||||
harfbuzz \
|
||||
ca-certificates \
|
||||
ttf-freefont \
|
||||
font-noto-cjk \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# 设置 Chromium 环境变量
|
||||
ENV BROWSER_PATH=/usr/bin/chromium-browser
|
||||
ENV CHROME_BIN=/usr/bin/chromium-browser
|
||||
|
||||
# 复制二进制文件
|
||||
COPY --from=builder /app/cursor2api .
|
||||
COPY --from=builder /app/config.yaml .
|
||||
COPY --from=builder /app/static ./static
|
||||
|
||||
# 创建非 root 用户
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
RUN chown -R appuser:appgroup /app
|
||||
|
||||
# 注意:Chromium 需要以特殊方式运行,暂时使用 root
|
||||
# USER appuser
|
||||
|
||||
EXPOSE 3010
|
||||
|
||||
CMD ["./cursor2api"]
|
||||
13
README.md
13
README.md
@@ -37,6 +37,19 @@ cursor2api/
|
||||
|
||||
## 快速开始
|
||||
|
||||
### Docker 部署 (推荐)
|
||||
|
||||
```bash
|
||||
# 使用 docker-compose
|
||||
docker-compose up -d
|
||||
|
||||
# 或者手动构建运行
|
||||
docker build -t cursor2api .
|
||||
docker run -d -p 3010:3010 --shm-size=2g cursor2api
|
||||
```
|
||||
|
||||
### 本地运行
|
||||
|
||||
```bash
|
||||
# 安装依赖
|
||||
go mod tidy
|
||||
|
||||
19
docker-compose.yml
Normal file
19
docker-compose.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
cursor2api:
|
||||
build: .
|
||||
container_name: cursor2api
|
||||
ports:
|
||||
- "3010:3010"
|
||||
environment:
|
||||
- PORT=3010
|
||||
- BROWSER_PATH=/usr/bin/chromium-browser
|
||||
volumes:
|
||||
- ./config.yaml:/app/config.yaml:ro
|
||||
restart: unless-stopped
|
||||
# Chromium 需要的安全设置
|
||||
security_opt:
|
||||
- seccomp:unconfined
|
||||
# 共享内存,避免 Chromium 崩溃
|
||||
shm_size: '2gb'
|
||||
Reference in New Issue
Block a user