1-27同步
This commit is contained in:
@@ -1,54 +1,45 @@
|
||||
# ===============================
|
||||
# 1) 构建依赖阶段
|
||||
# ===============================
|
||||
FROM python:3.12.9-alpine AS build
|
||||
FROM uswccr.ccs.tencentyun.com/lessie/python:3.12-slim AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 替换 Alpine 国内源
|
||||
RUN echo "https://mirrors.aliyun.com/alpine/v3.21/main/" > /etc/apk/repositories && \
|
||||
echo "https://mirrors.aliyun.com/alpine/v3.21/community/" >> /etc/apk/repositories
|
||||
# 使用 uv 官方镜像中的二进制文件(不用 pip install uv )
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uv/bin/uv
|
||||
|
||||
# 构建依赖
|
||||
RUN apk add --no-cache \
|
||||
gcc \
|
||||
musl-dev \
|
||||
libffi-dev \
|
||||
openssl-dev \
|
||||
curl
|
||||
|
||||
# 安装 uv
|
||||
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir uv
|
||||
|
||||
# uv 使用的 PyPI 镜像
|
||||
ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
|
||||
# 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/*
|
||||
|
||||
# 拷贝依赖定义(用于缓存)
|
||||
COPY uv.lock pyproject.toml ./
|
||||
|
||||
# 安装依赖到 .venv
|
||||
RUN uv sync --no-dev
|
||||
# 使用 uv 安装依赖(--frozen 确保锁定版本)
|
||||
RUN /uv/bin/uv sync --frozen --no-dev --no-install-project
|
||||
|
||||
# ===============================
|
||||
# 2) 运行阶段
|
||||
# ===============================
|
||||
FROM python:3.12.9-alpine AS runtime
|
||||
FROM uswccr.ccs.tencentyun.com/lessie/python:3.12-slim AS runtime
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 替换 Alpine 国内源
|
||||
RUN echo "https://mirrors.aliyun.com/alpine/v3.21/main/" > /etc/apk/repositories && \
|
||||
echo "https://mirrors.aliyun.com/alpine/v3.21/community/" >> /etc/apk/repositories
|
||||
# 设置时区 (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/*
|
||||
|
||||
# 时区
|
||||
RUN apk add --no-cache tzdata && \
|
||||
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
# 拷贝 uv、虚拟环境、Python 运行库
|
||||
COPY --from=build /usr/local/bin/uv /usr/local/bin/uv
|
||||
# 拷贝 uv、虚拟环境
|
||||
COPY --from=build /uv/bin/uv /usr/local/bin/uv
|
||||
COPY --from=build /app/.venv /app/.venv
|
||||
COPY --from=build /usr/local/lib/python3.12 /usr/local/lib/python3.12
|
||||
|
||||
# 拷贝代码
|
||||
COPY . .
|
||||
|
||||
Reference in New Issue
Block a user