Spaces:
Running
Running
| # 🎯 前端构建阶段 | |
| FROM node:18-alpine AS frontend-builder | |
| # 安装 git | |
| RUN apk add --no-cache git | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # 克隆仓库 | |
| ARG GIT_REPO_URL=https://github.com/Wei-Shaw/claude-relay-service.git | |
| ARG GIT_BRANCH=main | |
| RUN git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO_URL} . | |
| # 构建前端 | |
| WORKDIR /app/web/admin-spa | |
| RUN npm ci && npm run build | |
| # 🐳 主应用阶段 | |
| FROM node:18-alpine | |
| # 📋 设置标签 | |
| LABEL maintainer="claude-relay-service@example.com" | |
| LABEL description="Claude Code API Relay Service" | |
| LABEL version="1.0.0" | |
| # 🔧 安装系统依赖和 git | |
| RUN apk add --no-cache \ | |
| curl \ | |
| dumb-init \ | |
| sed \ | |
| git \ | |
| && rm -rf /var/cache/apk/* | |
| # 📁 设置工作目录 | |
| WORKDIR /app | |
| # 克隆仓库 | |
| ARG GIT_REPO_URL=https://github.com/Wei-Shaw/claude-relay-service.git | |
| ARG GIT_BRANCH=main | |
| RUN git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO_URL} . | |
| # 🔽 安装依赖 (生产环境) | |
| RUN npm ci --only=production && \ | |
| npm cache clean --force | |
| # 📦 从构建阶段复制前端产物 | |
| COPY --from=frontend-builder /app/web/admin-spa/dist /app/web/admin-spa/dist | |
| # 🔧 设置启动脚本权限 | |
| RUN chmod +x docker-entrypoint.sh && \ | |
| cp docker-entrypoint.sh /usr/local/bin/ | |
| # 📁 创建必要目录并设置权限 | |
| RUN mkdir -p logs data temp config && \ | |
| chmod -R 777 /app/logs /app/data /app/temp /app/config | |
| # 🔧 预先创建配置文件并设置权限 | |
| RUN if [ ! -f "/app/config/config.js" ] && [ -f "/app/config/config.example.js" ]; then \ | |
| cp /app/config/config.example.js /app/config/config.js; \ | |
| fi && \ | |
| chmod 777 /app/config/config.js 2>/dev/null || true | |
| # 🔧 设置整个应用目录权限 | |
| RUN chmod -R 777 /app | |
| # 🌐 暴露端口 | |
| EXPOSE 3000 | |
| # 🏥 健康检查 | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:3000/health || exit 1 | |
| # 🚀 启动应用 | |
| ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"] | |
| CMD ["node", "src/app.js"] |