168 lines
4.3 KiB
Docker
168 lines
4.3 KiB
Docker
# ============ 构建阶段 ============
|
|
FROM ubuntu:24.04 AS builder
|
|
|
|
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 \
|
|
git \
|
|
build-essential \
|
|
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 pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
# 创建虚拟环境(解决 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
|
|
|
|
# 创建启动脚本
|
|
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 ["bash"]
|