150 lines
5.8 KiB
Docker
150 lines
5.8 KiB
Docker
# ============================================================================
|
||
# 基础镜像 Dockerfile - master-rcoder-base
|
||
# ============================================================================
|
||
# 此镜像包含所有运行时依赖、工具链和环境配置,不包含业务代码
|
||
# 构建命令: make docker-build-master-base
|
||
# 平时不需要重新构建,只有在修改系统依赖时才需要重新构建
|
||
# ============================================================================
|
||
|
||
FROM node:22
|
||
|
||
# 设置环境变量
|
||
ENV TZ=Asia/Shanghai
|
||
|
||
# 使用 LinuxMirrors 一键配置阿里云镜像源
|
||
# 参考: https://github.com/SuperManito/LinuxMirrors
|
||
# node:22 基础镜像已预装 curl,可直接执行脚本配置镜像源
|
||
RUN curl -sSL https://linuxmirrors.cn/main.sh | bash -s -- \
|
||
--source mirrors.aliyun.com \
|
||
--protocol https \
|
||
--use-intranet-source false \
|
||
--install-epel false \
|
||
--backup false \
|
||
--upgrade-software false \
|
||
--clean-cache true \
|
||
--ignore-backup-tips
|
||
|
||
# 安装必要的运行时依赖(apt 包管理器)
|
||
RUN apt-get update && apt-get install -y \
|
||
ca-certificates \
|
||
curl \
|
||
wget \
|
||
gnupg \
|
||
unzip \
|
||
zip \
|
||
tzdata \
|
||
lsof \
|
||
iproute2 \
|
||
net-tools \
|
||
nginx \
|
||
vim \
|
||
fonts-liberation \
|
||
lsb-release \
|
||
xdg-utils \
|
||
chromium \
|
||
chromium-driver \
|
||
&& rm -rf /var/lib/apt/lists/* \
|
||
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
|
||
&& echo $TZ > /etc/timezone
|
||
|
||
# 复制 npmrc 配置镜像(使用国内镜像加速)
|
||
COPY .npmrc /root/.npmrc
|
||
|
||
# 配置 npm 使用国内镜像源
|
||
RUN npm config set registry https://registry.npmmirror.com
|
||
|
||
# 安装 pnpm
|
||
RUN npm install -g pnpm
|
||
|
||
# 配置 pnpm 使用国内镜像源
|
||
RUN pnpm config set registry https://registry.npmmirror.com
|
||
|
||
# 创建 pnpm 全局存储目录
|
||
RUN mkdir -p /app/project_workspace/.pnpm-store
|
||
|
||
# 配置 pnpm 使用新的存储路径
|
||
RUN pnpm config set store-dir /app/project_workspace/.pnpm-store
|
||
|
||
# 配置 yarn 使用国内镜像源
|
||
RUN yarn config set registry https://registry.npmmirror.com
|
||
|
||
# 安装 vite(最新版本)
|
||
RUN npm install -g vite@latest
|
||
|
||
# 安装额外的命令工具(强制更新到最新版本)
|
||
RUN npm install -g @zed-industries/claude-code-acp@latest
|
||
|
||
# 安装 Claude CLI 工具(强制更新到最新版本)
|
||
RUN npm install -g @anthropic-ai/claude-code@latest
|
||
|
||
# 安装 OpenAI Codex(强制更新到最新版本)
|
||
RUN npm install -g @openai/codex@latest
|
||
|
||
# 安装 Chrome DevTools MCP(强制更新到最新版本)
|
||
RUN npm install -g chrome-devtools-mcp@latest
|
||
|
||
# 安装 Bun(使用 npm 从阿里云 npmmirror 安装 prebuilt 二进制,避免从 bun.sh/install 走 GitHub 下载不稳定)
|
||
# bun 的 npm 包通过 optionalDependencies 引入平台特定二进制(如 @oven/bun-linux-x64),npmmirror 已镜像
|
||
# --prefix=/usr/local 让 bun 安装到 /usr/local/bin/bun(默认就在 PATH 中,无需额外 ENV)
|
||
RUN npm install -g --prefix=/usr/local --registry=https://registry.npmmirror.com bun && \
|
||
/usr/local/bin/bun --version
|
||
|
||
# Bun 运行时配置(bun install 使用的 registry)
|
||
RUN echo '[install]' > /root/.bunfig.toml && \
|
||
echo 'registry = "https://registry.npmmirror.com"' >> /root/.bunfig.toml && \
|
||
echo '' >> /root/.bunfig.toml && \
|
||
echo '[install.scopes]' >> /root/.bunfig.toml && \
|
||
# @upstash scope 走 npmmirror 加速:bun 装 @upstash 包默认从这里下载,国内速度快
|
||
# 注意:bun 与 npmmirror 的 tarball 校验存在偶发性 bug(#21493),但 docker build 期
|
||
# 预装 context7-mcp 时已用 --registry npmjs.org 命令行参数覆盖,避开 build 失败
|
||
# 运行时 bunx @upstash/context7-mcp 会命中 ~/.bun/install/global 全局缓存,无需再下载
|
||
echo '"@upstash" = "https://registry.npmmirror.com"' >> /root/.bunfig.toml
|
||
|
||
# 安装 python3-pip(node:22 基础镜像默认不带 Python,用 pip 装 uv 需要先安装)
|
||
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip && \
|
||
rm -rf /var/lib/apt/lists/*
|
||
|
||
# 安装 uv 并验证(使用 pip 从阿里云 PyPI 镜像安装,避免从 astral.sh 下载二进制慢/不稳定)
|
||
# --break-system-packages: Debian 12+ 的 PEP 668 限制,系统 Python 默认不允许直接 pip install
|
||
RUN pip3 install --break-system-packages --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple uv && \
|
||
uv --version || (echo "ERROR: uv installation failed" && exit 1)
|
||
|
||
# 设置 uv 镜像加速地址
|
||
ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
|
||
|
||
# 设置工作目录
|
||
WORKDIR /app
|
||
|
||
# 创建 bin 目录
|
||
RUN mkdir -p /app/bin
|
||
|
||
# 预安装 MCP 工具到 uv 缓存中
|
||
RUN uv tool install mcp-server-fetch
|
||
|
||
# 预安装 context7 MCP 工具(Bun 全局安装)
|
||
# 代码里通过 bunx 调用 MCP,预装到 bun 全局后 bunx 可直接命中 ~/.bun/install/global,无需运行时再下载
|
||
RUN bun add -g @upstash/context7-mcp
|
||
|
||
# 创建 Claude Code 配置目录并禁用 webfetch 功能,添加 MCP 工具
|
||
RUN mkdir -p /root/.claude && \
|
||
echo '{"permissions":{"deny":["WebFetch", "WebSearch"]},"mcpServers":{"mcp-fetch":{"args":["mcp-server-fetch"],"command":"uvx"},"chrome-devtools":{"command":"npx","args":["-y","chrome-devtools-mcp@latest"]}}}' > /root/.claude/settings.json
|
||
|
||
# 添加所有工具安装路径到 PATH
|
||
ENV PNPM_HOME="/home/user/.local/share/pnpm" \
|
||
PATH="/app/bin:/root/.local/bin:/home/user/.local/bin:/home/user/.local/share/pnpm:/opt/cargo/bin:/usr/local/bin:${PATH}"
|
||
|
||
|
||
# 清理默认nginx配置以避免冲突
|
||
RUN rm -f /etc/nginx/sites-enabled/default && \
|
||
rm -f /etc/nginx/conf.d/default.conf
|
||
|
||
# ============================================================================
|
||
# 基础镜像构建完成
|
||
# ============================================================================
|
||
# 此处不设置 ENTRYPOINT/CMD,由最终镜像设置
|
||
|
||
# 暴露端口(供最终镜像使用)
|
||
EXPOSE 8086
|
||
EXPOSE 60000
|
||
EXPOSE 80
|