From 6c3d38a63644567d13b0276d59525b3e77907ebe Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Tue, 16 Dec 2025 15:21:36 +0800 Subject: [PATCH] =?UTF-8?q?base=E4=BE=9D=E8=B5=96=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/schoolNews/Dockerfile.base-serv | 95 ++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/docker/schoolNews/Dockerfile.base-serv b/docker/schoolNews/Dockerfile.base-serv index 05dfed9..86f2066 100644 --- a/docker/schoolNews/Dockerfile.base-serv +++ b/docker/schoolNews/Dockerfile.base-serv @@ -8,37 +8,105 @@ FROM eclipse-temurin:21-jre # 设置环境变量 ENV LANG=C.UTF-8 \ LC_ALL=C.UTF-8 \ - TZ=Asia/Shanghai + TZ=Asia/Shanghai \ + PYTHONUNBUFFERED=1 \ + PYTHONIOENCODING=UTF-8 \ + PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \ + PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn + +# 设置阿里云Debian源和时区 +RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib" > /etc/apt/sources.list && \ + echo "deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo "deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main non-free non-free-firmware contrib" >> /etc/apt/sources.list && \ + echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid && \ + apt-get update && apt-get install -y --no-install-recommends gnupg2 ca-certificates # 安装系统依赖和工具 RUN apt-get update && \ - apt-get install -y \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ # Python环境 python3 \ python3-pip \ python3-venv \ + python3-dev \ + # 编译工具 + build-essential \ # 网络和诊断工具 netcat-traditional \ curl \ wget \ - # MySQL客户端 + dnsutils \ + iputils-ping \ + # 系统工具 + procps \ + htop \ + vim \ + less \ + # 数据库客户端 default-mysql-client \ + # 字体和图形库 + fonts-liberation \ + fonts-noto-color-emoji \ + fonts-noto-cjk \ + # Chrome依赖 + libxss1 \ + libx11-xcb1 \ + libxcb1 \ + libxcomposite1 \ + libxcursor1 \ + libxdamage1 \ + libxi6 \ + libxtst6 \ + libnss3 \ + libcups2 \ + libxrandr2 \ + libasound2 \ + libatk1.0-0 \ + libatk-bridge2.0-0 \ + libpangocairo-1.0-0 \ + libgtk-3-0 \ + # 图片处理 + libjpeg-dev \ + zlib1g-dev \ + libpng-dev \ + # 其他依赖 + libffi-dev \ + libssl-dev \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ + && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone -# 临时复制requirements.txt用于安装依赖 +# 设置Python3为默认Python +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \ + && update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 + +WORKDIR /app + +# 配置pip使用清华源 +RUN mkdir -p /etc/pip && \ + echo "[global]" > /etc/pip/pip.conf && \ + echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> /etc/pip/pip.conf && \ + echo "trusted-host = pypi.tuna.tsinghua.edu.cn" >> /etc/pip/pip.conf + +# 安装常用Python工具和爬虫依赖 COPY schoolNewsCrawler/requirements.txt /tmp/requirements.txt -# 安装Python爬虫依赖(一次性安装到基础镜像) RUN echo "========================================" && \ echo "安装Python爬虫依赖到基础镜像" && \ echo "========================================" && \ - # 配置pip使用国内镜像源(清华源) - python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ - python3 -m pip --version && \ - echo "" && \ - # Python 3.12 引入了 PEP 668 规范,需要添加 --break-system-packages + # 确保pip是最新版本 + python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel && \ + # 安装依赖 python3 -m pip install --no-cache-dir --break-system-packages -r /tmp/requirements.txt && \ + # 清理缓存 + python3 -m pip cache purge && \ + # 验证安装 echo "" && \ echo "✅ 爬虫依赖安装完成" && \ python3 -m pip list | grep -E "(beautifulsoup4|crawl4ai|selenium|pydantic|requests|loguru)" && \ @@ -46,9 +114,12 @@ RUN echo "========================================" && \ rm -f /tmp/requirements.txt # 创建应用目录结构 -WORKDIR /app RUN mkdir -p /app/config /app/logs /app/uploads /app/crawler +# 健康检查 +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8080/actuator/health || exit 1 + # 镜像元数据 LABEL maintainer="School News Team" \ description="Base image for school-news backend service with Python dependencies" \