Some checks are pending
Build and Push Docker Images / changes (push) Waiting to run
Build and Push Docker Images / build-backend (push) Blocked by required conditions
Build and Push Docker Images / build-frontend (push) Blocked by required conditions
Build and Push Docker Images / build-admin-frontend (push) Blocked by required conditions
34 lines
937 B
Docker
34 lines
937 B
Docker
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# 设置环境变量
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1
|
|
|
|
# 安装系统工具 (curl用于可能的健康检查)
|
|
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
# 1. 缓存层:仅复制依赖定义并安装
|
|
# 创建伪造的 app 目录以满足 pip install . 的要求
|
|
COPY pyproject.toml .
|
|
RUN mkdir app && touch app/__init__.py
|
|
RUN pip install --no-cache-dir .
|
|
|
|
# 2. 源码层:复制真实代码
|
|
COPY app ./app
|
|
COPY alembic ./alembic
|
|
COPY alembic.ini .
|
|
|
|
# 再次安装本身(不带依赖),确保源码更新被标记为已安装
|
|
RUN pip install --no-cache-dir --no-deps .
|
|
|
|
# 创建静态文件目录
|
|
RUN mkdir -p static/images
|
|
|
|
# 暴露端口
|
|
EXPOSE 8000
|
|
|
|
# 默认启动命令(可被 docker-compose 覆盖)
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|