Files
jenkins-pipeline/Dockerfile/python/apex/apex_dockerfile

54 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

2025-12-17 17:32:04 +08:00
# ===============================
# 1) 构建依赖阶段
# ===============================
2026-01-27 18:21:54 +08:00
FROM uswccr.ccs.tencentyun.com/lessie/python:3.12-slim AS build
2025-12-17 17:32:04 +08:00
WORKDIR /app
2026-01-27 18:21:54 +08:00
# 使用 uv 官方镜像中的二进制文件(不用 pip install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uv/bin/uv
2025-12-17 17:32:04 +08:00
2026-01-27 18:21:54 +08:00
# APT 源替换 + 安装依赖(合并为一个 RUN最大化缓存
RUN set -eux; \
sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources; \
apt-get update; \
apt-get install -y --no-install-recommends build-essential git; \
rm -rf /var/lib/apt/lists/*
2025-12-17 17:32:04 +08:00
# 拷贝依赖定义(用于缓存)
COPY uv.lock pyproject.toml ./
2026-01-27 18:21:54 +08:00
# 使用 uv 安装依赖(--frozen 确保锁定版本)
RUN /uv/bin/uv sync --frozen --no-dev --no-install-project
2025-12-17 17:32:04 +08:00
# ===============================
# 2) 运行阶段
# ===============================
2026-01-27 18:21:54 +08:00
FROM uswccr.ccs.tencentyun.com/lessie/python:3.12-slim AS runtime
2025-12-17 17:32:04 +08:00
WORKDIR /app
2026-01-27 18:21:54 +08:00
# 设置时区 (Debian 方式)
RUN set -eux; \
sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources; \
apt-get update; \
apt-get install -y --no-install-recommends tzdata; \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
echo "Asia/Shanghai" > /etc/timezone; \
rm -rf /var/lib/apt/lists/*
# 拷贝 uv、虚拟环境
COPY --from=build /uv/bin/uv /usr/local/bin/uv
2025-12-17 17:32:04 +08:00
COPY --from=build /app/.venv /app/.venv
# 拷贝代码
COPY . .
ENV APP_ENV=dev \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH"
EXPOSE 8200
CMD ["uv", "run", "main.py", "--port", "8200"]