mirror of
https://github.com/7836246/cursor2api.git
synced 2026-09-03 07:20:02 +08:00
feat: 增加基于现代多阶段构建的生产级 Docker 环境配置
- 采用最新的 Node.js 22 LTS (Alpine) 作为底座。 - 引入二阶段构建 (Builder/Runner),隔离源码与产物,极致缩小最终镜像体积。 - 采用非 root (cursor UID=1001) 用户权限组执行程序,保证生产环境安全性。 - 提供了配套的 .dockerignore 和 docker-compose.yml 服务编排文件,支持传参 SOCKS 代理等。
This commit is contained in:
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@@ -0,0 +1,16 @@
|
||||
node_modules
|
||||
dist
|
||||
.vscode
|
||||
.claude
|
||||
.idea
|
||||
.git
|
||||
.gitignore
|
||||
*.log
|
||||
http.log
|
||||
npm-debug.log
|
||||
.DS_Store
|
||||
|
||||
# 构建中间产物和测试文件
|
||||
deploy.sh
|
||||
cursor2api_deployment.zip
|
||||
test*.txt
|
||||
47
Dockerfile
Normal file
47
Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
||||
# ==== Stage 1: 构建阶段 (Builder) ====
|
||||
FROM node:22-alpine AS builder
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 仅拷贝包配置并安装所有依赖项(利用 Docker 缓存层)
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
# 拷贝项目源代码并执行 TypeScript 编译
|
||||
COPY tsconfig.json ./
|
||||
COPY src ./src
|
||||
COPY jscode ./jscode
|
||||
RUN npm run build
|
||||
|
||||
# ==== Stage 2: 生产运行阶段 (Runner) ====
|
||||
FROM node:22-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 设置为生产环境
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# 出于安全考虑,避免使用 root 用户运行服务
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
adduser --system --uid 1001 cursor
|
||||
|
||||
# 拷贝包配置并仅安装生产环境依赖(极大减小镜像体积)
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --omit=dev \
|
||||
&& npm cache clean --force
|
||||
|
||||
# 从 builder 阶段拷贝编译后的产物
|
||||
COPY --from=builder --chown=cursor:nodejs /app/dist ./dist
|
||||
# 拷贝必要的运行时资源目录
|
||||
COPY --from=builder --chown=cursor:nodejs /app/jscode ./jscode
|
||||
|
||||
# 明确并赋予权限,因为在脚本验证里我们需要写入 /tmp
|
||||
# 默认情况下 Alpine 的 /tmp 对所有用户都可写,这步安全地确保用户权限
|
||||
USER cursor
|
||||
|
||||
# 声明对外暴露的端口
|
||||
EXPOSE 3010
|
||||
|
||||
# 启动服务
|
||||
CMD ["npm", "start"]
|
||||
24
docker-compose.yml
Normal file
24
docker-compose.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
services:
|
||||
cursor2api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: cursor2api:latest
|
||||
container_name: cursor2api
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3010:3010"
|
||||
# volumes:
|
||||
# 如果你有外部的 config.yaml 文件,可以取消下面这行的注释来挂载配置文件
|
||||
# - ./config.yaml:/app/config.yaml:ro
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3010
|
||||
- TIMEOUT=120
|
||||
# ⚠️ 部署到海外机器无需代理,如果在国内云,取消注释并填入你的本机 http/socks 代理
|
||||
# - PROXY=http://host.docker.internal:7890
|
||||
|
||||
# [可选环境变量] 以下变量如果你在此声明,将会覆盖 config.yaml 的配置逻辑:
|
||||
# - CURSOR_MODEL=anthropic/claude-sonnet-4.6
|
||||
# - SCRIPT_URL=https://...
|
||||
# - FP=ey...
|
||||
Reference in New Issue
Block a user