102 lines
3.2 KiB
Docker
102 lines
3.2 KiB
Docker
# 第一阶段:构建环境
|
||
FROM ubuntu:20.04 AS builder
|
||
|
||
# 避免交互式前端
|
||
ENV DEBIAN_FRONTEND=noninteractive
|
||
|
||
# 设置DNS环境变量,避免网络连接问题
|
||
ENV RES_OPTIONS="timeout:1 attempts:1 rotate"
|
||
ENV GETDNS_STUB_TIMEOUT=100
|
||
|
||
# 使用阿里云镜像源加速
|
||
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
|
||
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
|
||
|
||
# 安装构建工具和依赖
|
||
RUN apt-get update && apt-get install -y \
|
||
build-essential \
|
||
cmake \
|
||
git \
|
||
curl \
|
||
libssl-dev \
|
||
python3-dev \
|
||
python3-pip \
|
||
ca-certificates \
|
||
gnupg \
|
||
--no-install-recommends \
|
||
&& apt-get clean \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 设置pip镜像源(阿里云)
|
||
RUN python3 -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip && \
|
||
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
|
||
|
||
# 安装Node.js
|
||
RUN mkdir -p /etc/apt/keyrings && \
|
||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
|
||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
|
||
apt-get update && \
|
||
apt-get install -y nodejs && \
|
||
apt-get clean && \
|
||
rm -rf /var/lib/apt/lists/*
|
||
|
||
# 设置npm淘宝镜像
|
||
RUN npm config set registry https://registry.npmmirror.com
|
||
|
||
# 安装项目所需的npm包
|
||
RUN npm install -g @modelcontextprotocol/server-puppeteer \
|
||
@modelcontextprotocol/server-filesystem \
|
||
@kevinwatt/shell-mcp \
|
||
@modelcontextprotocol/server-everything
|
||
|
||
# 创建工作目录
|
||
WORKDIR /app
|
||
|
||
# 第二阶段:运行环境(包含所有依赖但没有构建工具)
|
||
FROM ubuntu:20.04 AS release
|
||
|
||
# 避免交互式前端
|
||
ENV DEBIAN_FRONTEND=noninteractive
|
||
|
||
# 设置DNS环境变量,避免网络连接问题
|
||
ENV RES_OPTIONS="timeout:1 attempts:1 rotate"
|
||
ENV GETDNS_STUB_TIMEOUT=100
|
||
|
||
# 使用阿里云镜像源加速
|
||
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
|
||
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
|
||
|
||
# 安装运行时依赖(最小化)
|
||
RUN apt-get update && apt-get install -y \
|
||
libssl-dev \
|
||
python3 \
|
||
ca-certificates \
|
||
curl \
|
||
--no-install-recommends \
|
||
&& apt-get clean \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 安装Node.js
|
||
RUN mkdir -p /etc/apt/keyrings && \
|
||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
|
||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
|
||
apt-get update && \
|
||
apt-get install -y nodejs && \
|
||
apt-get clean && \
|
||
rm -rf /var/lib/apt/lists/*
|
||
|
||
# 设置npm淘宝镜像
|
||
RUN npm config set registry https://registry.npmmirror.com
|
||
|
||
# 从构建阶段复制全局npm包
|
||
COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules
|
||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||
|
||
# 创建工作目录
|
||
WORKDIR /app
|
||
|
||
# 创建构建目录
|
||
RUN mkdir -p /app/build
|
||
|
||
# 设置默认命令为bash
|
||
CMD ["/bin/bash"] |