Files
docker-registry/kami-spider-monorepo/Dockerfile.base
danial 716a72b8ab feat(ci): 添加 Spider Base 镜像构建和部署流水线
- 新增 .drone.yml 配置,实现基于 SSH 的自动构建和推送 Spider Base 镜像
- 检测 kami-spider-monorepo 目录代码变动,变动时触发基础镜像构建
- 基础镜像包含系统依赖、Python 环境、Playwright 及所有项目依赖
- 优化 Dockerfile,将应用镜像基于该预构建基础镜像构建,显著提升构建速度
- 新增 Makefile,标准化基础镜像和应用镜像的构建、测试、推送及清理流程
- 增加详细的 README,指导开发者快速上手构建和使用基础镜像
- 添加构建脚本 build-base-image.sh,实现基础镜像的统一构建及推送
- 引入生产环境入口脚本 docker-entrypoint.sh,优化启动流程和信号处理
- 统一依赖管理(pyproject.toml、uv.lock),确保基础镜像依赖完整一致
- 设定健康检查,提升容器运行稳定性和可监控性
2025-11-09 15:08:38 +08:00

83 lines
2.2 KiB
Docker

# Combined Base Image for kami_spider applications
# Contains Python, system dependencies, UV package manager, and all Python packages with Playwright
# Build arguments
ARG USE_PROXY=0
FROM python:3.13-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PATH="/app/.venv/bin:$PATH" \
UV_CACHE_DIR=/tmp/uv-cache \
PYDEVD_DISABLE=1 \
PYDEVD_DISABLE_FILE_VALIDATION=1 \
PYCHARM_DEBUG="false" \
PYTEST_CURRENT_TEST="false"
# Install system dependencies for Playwright and build tools
RUN apt-get update && apt-get install -y \
# Build tools
gcc \
g++ \
curl \
wget \
gnupg \
ca-certificates \
# Playwright runtime dependencies
fonts-liberation \
libnss3 \
libatk-bridge2.0-0 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
libgbm1 \
libasound2 \
libcups2t64 \
libxfixes3 \
libcairo2 \
libpango-1.0-0 \
# Cleanup
&& rm -rf /var/lib/apt/lists/*
# Install UV package manager
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Create non-root user with home directory
RUN groupadd -r appuser && useradd -r -g appuser -d /home/appuser -m appuser
# Set up directories with proper permissions
RUN mkdir -p /app \
&& mkdir -p /home/appuser/.cache \
&& chown -R appuser:appuser /app /home/appuser
# Switch to non-root user for dependency installation
USER appuser
# Set working directory
WORKDIR /app
# Copy dependency files
COPY --chown=appuser:appuser pyproject.toml ./
COPY --chown=appuser:appuser uv.lock ./
# Install Python dependencies using UV
RUN if [ "$USE_PROXY" = "1" ]; then \
uv sync --frozen --no-dev --no-install-project --index-url https://pypi.tuna.tsinghua.edu.cn/simple/; \
else \
uv sync --frozen --no-dev --no-install-project; \
fi
# Install Playwright browsers with dependencies
RUN .venv/bin/playwright install chromium --with-deps && \
.venv/bin/playwright install-deps chromium
# Label the image
LABEL maintainer="kami-spider-team" \
version="1.0.0" \
description="Complete base image for kami_spider applications with Python, UV, all dependencies and Playwright browsers"