更改目录
This commit is contained in:
62
Dockerfile/python/apex/apex_dockerfile
Normal file
62
Dockerfile/python/apex/apex_dockerfile
Normal file
@@ -0,0 +1,62 @@
|
||||
# ===============================
|
||||
# 1) 构建依赖阶段
|
||||
# ===============================
|
||||
FROM python:3.12.9-alpine 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
|
||||
|
||||
# 构建依赖
|
||||
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/
|
||||
|
||||
# 拷贝依赖定义(用于缓存)
|
||||
COPY uv.lock pyproject.toml ./
|
||||
|
||||
# 安装依赖到 .venv
|
||||
RUN uv sync --no-dev
|
||||
|
||||
# ===============================
|
||||
# 2) 运行阶段
|
||||
# ===============================
|
||||
FROM python:3.12.9-alpine 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
|
||||
|
||||
# 时区
|
||||
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
|
||||
COPY --from=build /app/.venv /app/.venv
|
||||
COPY --from=build /usr/local/lib/python3.12 /usr/local/lib/python3.12
|
||||
|
||||
# 拷贝代码
|
||||
COPY . .
|
||||
|
||||
ENV APP_ENV=dev \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH="/app/.venv/bin:$PATH"
|
||||
|
||||
EXPOSE 8200
|
||||
|
||||
CMD ["uv", "run", "main.py", "--port", "8200"]
|
||||
Reference in New Issue
Block a user