增加多阶段构建,并在镜像中构建指定版本的vina 便于使用。

This commit is contained in:
2025-10-15 21:52:49 +08:00
parent 7ac0e58599
commit 1248cd187d
4 changed files with 200 additions and 107 deletions

View File

@@ -1,69 +1,167 @@
# 使用 Ubuntu 22.04 作为基础镜像(使用腾讯云镜像源)
FROM ccr.ccs.tencentyun.com/library/ubuntu:22.04
# ============ 构建阶段 ============
FROM ubuntu:24.04 AS builder
# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/root/.pixi/bin:$PATH"
# 配置 APT 镜像源(使用阿里云镜像)
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 <<EOF
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
EOF
# 安装系统依赖
RUN apt-get update && apt-get install -y \
curl \
wget \
# 安装构建依赖
RUN <<EOF
apt-get update
apt-get install -y \
git \
build-essential \
ca-certificates \
gnupg \
lsb-release \
&& rm -rf /var/lib/apt/lists/*
libboost-all-dev \
swig \
python3-dev \
python3-pip \
python3-venv
rm -rf /var/lib/apt/lists/*
EOF
# 创建构建虚拟环境并安装必要的 Python 包
RUN <<EOF
echo "创建构建虚拟环境..."
python3 -m venv /opt/build-venv
echo "配置 pip 镜像源..."
/opt/build-venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
echo "安装构建依赖包..."
/opt/build-venv/bin/pip install numpy packaging setuptools wheel
echo "构建环境准备完成"
EOF
# 克隆 AutoDock Vina 源码
ARG VINA_VERSION=1.2.7
RUN <<EOF
git clone https://github.com/ccsb-scripps/AutoDock-Vina.git /tmp/AutoDock-Vina
cd /tmp/AutoDock-Vina
git checkout v${VINA_VERSION}
EOF
# 编译 Python wheel 包
RUN <<EOF
cd /tmp/AutoDock-Vina
echo "AutoDock Vina 源码结构:"
find . -name "setup.py" -type f
echo "检查 build/python 目录:"
ls -la build/python/ 2>/dev/null || echo "build/python 目录不存在"
echo "检查根目录的 setup.py:"
ls -la setup.py 2>/dev/null || echo "根目录没有 setup.py"
# 尝试在根目录构建
if [ -f "setup.py" ]; then
echo "在根目录构建 wheel 包..."
/opt/build-venv/bin/python setup.py bdist_wheel
else
echo "在 build/python 目录构建 wheel 包..."
cd build/python
/opt/build-venv/bin/python setup.py bdist_wheel
fi
echo "构建完成,查找所有 wheel 文件:"
find /tmp/AutoDock-Vina -name "*.whl" -type f
mkdir -p /wheels
find /tmp/AutoDock-Vina -name "*.whl" -type f -exec cp {} /wheels/ \;
echo "复制的 wheel 文件:"
ls -la /wheels/
EOF
# 编译二进制可执行文件
RUN <<EOF
cd /tmp/AutoDock-Vina/build/linux/release
make
mkdir -p /binaries
cp vina /binaries/
cp vina_split /binaries/
EOF
# ============ 运行阶段 ============
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# 配置镜像源(使用阿里云镜像)
RUN <<EOF
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
EOF
# 安装运行时依赖
RUN <<EOF
apt-get update
apt-get install -y \
python3 \
python3-pip \
python3-venv \
libboost-system1.83.0 \
libboost-thread1.83.0 \
libboost-serialization1.83.0 \
libboost-filesystem1.83.0 \
libboost-program-options1.83.0
rm -rf /var/lib/apt/lists/*
EOF
# 配置 pip 镜像源
RUN mkdir -p /root/.pip && \
echo "[global]" > /root/.pip/pip.conf && \
echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> /root/.pip/pip.conf && \
echo "trusted-host = pypi.tuna.tsinghua.edu.cn" >> /root/.pip/pip.conf
RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 安装 pixi
RUN curl -fsSL https://pixi.sh/install.sh | bash
# 创建虚拟环境(解决 Python 3.12 PEP 668 保护问题)
RUN <<EOF
echo "创建虚拟环境..."
python3 -m venv /opt/venv
echo "虚拟环境创建完成,检查路径:"
ls -la /opt/venv/bin/
echo "升级 pip..."
/opt/venv/bin/pip install --upgrade pip
echo "虚拟环境准备完成"
EOF
# 从构建阶段复制 wheel 包并安装到虚拟环境
COPY --from=builder /wheels/*.whl /tmp/
RUN <<EOF
/opt/venv/bin/pip install /tmp/*.whl
rm -rf /tmp/*.whl
EOF
# 设置虚拟环境路径
ENV PATH="/opt/venv/bin:$PATH"
# 从构建阶段复制二进制文件
COPY --from=builder /binaries/* /usr/local/bin/
RUN chmod +x /usr/local/bin/vina*
# 设置工作目录
WORKDIR /app
# 复制项目文件
COPY . .
# 创建 bin 目录
RUN mkdir -p bin
# 下载 AutoDock Vina 二进制文件
ARG VINA_VERSION=1.2.7
ARG VINA_PLATFORM=mac_aarch64
ARG DOWNLOAD_VINA=true
RUN if [ "$DOWNLOAD_VINA" = "true" ]; then \
curl -L -o ./bin/vina_${VINA_VERSION}_${VINA_PLATFORM} https://github.com/ccsb-scripps/AutoDock-Vina/releases/download/v${VINA_VERSION}/vina_${VINA_VERSION}_${VINA_PLATFORM} && \
curl -L -o ./bin/vina_split_${VINA_VERSION}_${VINA_PLATFORM} https://github.com/ccsb-scripps/AutoDock-Vina/releases/download/v${VINA_VERSION}/vina_split_${VINA_VERSION}_${VINA_PLATFORM} && \
chmod +x ./bin/vina_*; \
fi
# 添加平台支持并安装 pixi 包
RUN /root/.pixi/bin/pixi workspace platform add linux-aarch64 && \
/root/.pixi/bin/pixi add rdkit openbabel meeko
# 设置环境变量
ENV PATH="/root/.pixi/bin:/app/bin:$PATH"
# 创建启动脚本
RUN echo '#!/bin/bash\n\
source /root/.bashrc\n\
exec "$@"' > /entrypoint.sh && \
chmod +x /entrypoint.sh
RUN <<EOF
cat > /entrypoint.sh << 'SCRIPT_EOF'
#!/bin/bash
echo "AutoDock Vina 环境已准备就绪 (Ubuntu 24.04 + Python 3.12 + Boost 1.83.0)"
echo "虚拟环境: \$(which python)"
echo "Python 版本: \$(python --version 2>&1)"
echo "Python 绑定测试:"
python -c "from vina import Vina; print('Vina Python 绑定可用')" 2>/dev/null || echo "Python 绑定不可用"
echo "命令行工具: vina --version"
vina --version 2>/dev/null || echo "vina 命令不可用"
echo "Boost 库信息:"
ldd /usr/local/bin/vina | grep boost || echo "无法获取 Boost 信息"
if [ "\$#" -eq 0 ]; then
echo "进入交互模式..."
exec /bin/bash
else
echo "执行命令: \$@"
exec "\$@"
fi
SCRIPT_EOF
chmod +x /entrypoint.sh
EOF
# 设置入口点
ENTRYPOINT ["/entrypoint.sh"]
# 默认命令
CMD ["/root/.pixi/bin/pixi", "shell"]
CMD ["bash"]