diff --git a/.jenkins/Dockerfile b/.jenkins/Dockerfile index e385a86..7a3a337 100644 --- a/.jenkins/Dockerfile +++ b/.jenkins/Dockerfile @@ -1,4 +1,3 @@ -# syntax=docker/dockerfile:1.7 # ============================================================ # Dockerfile:项目镜像(多阶段构建) # 基础镜像:python-base:3.12.8(RockyLinux 8 + Python 3.12.8 + mariadb-connector-c) @@ -8,7 +7,6 @@ # - runtime 继承基础镜像的 Python,只把依赖的 site-packages COPY 过来 # - MySQL 运行库(mariadb-connector-c)由基础镜像预置,runtime 无需重复安装 # - 源码 COPY 放在 pip install 之后,保护依赖层缓存 -# - 使用 BuildKit cache mount 加速 dnf / pip # # 构建参数 # VAR_BASE_IMAGE 基础镜像 @@ -62,9 +60,7 @@ ENV PYTHONUNBUFFERED=1 \ # bzip2-devel / libffi-devel # mariadb-devel 编译 mysqlclient(提供 .pc 文件) # pkgconf-pkg-config 提供 pkg-config 命令(mysqlclient 2.2.x 必需) -# 使用 BuildKit cache mount,重复构建不再重新下载 RPM -RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-cache \ - set -eux; \ +RUN set -eux; \ # 替换 dnf 源为阿里云镜像 sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \ @@ -72,7 +68,8 @@ RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-cache \ dnf install -y --setopt=install_weak_deps=False \ gcc gcc-c++ make \ openssl-devel bzip2-devel libffi-devel \ - mariadb-devel pkgconf-pkg-config + mariadb-devel pkgconf-pkg-config; \ + dnf clean all; rm -rf /var/cache/dnf # 配置 pip 国内镜像源(阿里云 PyPI) RUN pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple && \ @@ -86,9 +83,7 @@ COPY ${VAR_PYFILE_PATH}/requirements.txt ./ # 依赖装到 /opt/deps,与基础镜像 Python 目录解耦 # --prefix=/opt/deps 安装到独立目录,runtime 只 COPY 这个目录的产物 # uwsgi 生产环境 WSGI 服务器,单独安装 -# 使用 pip cache mount,重复构建不再重新下载 wheel -RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-cache \ - python3 -m pip install --prefix=/opt/deps -r requirements.txt && \ +RUN python3 -m pip install --prefix=/opt/deps -r requirements.txt && \ python3 -m pip install --prefix=/opt/deps uwsgi @@ -124,12 +119,12 @@ ENV PORT=${VAR_PORT} \ # 运行期依赖 # mariadb-connector-c 基础镜像已预置,无需重复安装 # net-tools 按需保留,如不需要可删 -RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-cache \ - set -eux; \ +RUN set -eux; \ sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \ -i.bak /etc/yum.repos.d/*.repo; \ - dnf install -y --setopt=install_weak_deps=False net-tools + dnf install -y --setopt=install_weak_deps=False net-tools; \ + dnf clean all; rm -rf /var/cache/dnf # 把 builder 编译好的 site-packages 和可执行文件拷到基础镜像 Python 对应目录 # 目标路径必须与基础镜像 Python 的实际 site-packages 一致