This commit is contained in:
aaron 2025-04-29 00:49:26 +08:00
parent 3a8ac86094
commit cd24db99cb
2 changed files with 46 additions and 33 deletions

View File

@ -1,43 +1,55 @@
FROM python:3.13-slim
FROM python:3.10-slim as builder
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
libc6-dev \
python3-dev \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /build
# 复制依赖文件
COPY requirements.txt .
# 安装依赖
RUN pip install --upgrade pip && \
pip install wheel setuptools && \
pip wheel --wheel-dir=/build/wheels -r requirements.txt
# 第二阶段:最终镜像
FROM python:3.10-slim
# 安装运行时依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 设置工作目录
WORKDIR /app
# 安装基本依赖
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# 从构建阶段复制预构建的wheel文件
COPY --from=builder /build/wheels /wheels
# 复制项目文件
COPY . /app/
# 安装预构建的wheel
RUN pip install --upgrade pip && \
pip install --no-index --find-links=/wheels /wheels/* && \
rm -rf /wheels
# # 创建虚拟环境, 先判断是否存在
# RUN if [ ! -d "venv" ]; then \
# python -m venv venv; \
# fi
# 复制应用代码
COPY . .
# # 激活虚拟环境
# RUN source venv/bin/activate
# 安装setuptools
RUN pip install setuptools
# 安装Python依赖
RUN pip install -r requirements.txt
# 设置环境变量
ENV PYTHONUNBUFFERED=1
# 设置Python路径
ENV PYTHONPATH=/app
# 创建配置文件目录
RUN mkdir -p /app/config
# 创建数据和日志目录
RUN mkdir -p /app/cryptoai/data /app/cryptoai/logs
# 创建数据目录
RUN mkdir -p /app/cryptoai/data /app/logs
# 暴露端口如果有Web服务
# EXPOSE 8000
# 设置容器启动命令
ENTRYPOINT ["python", "run.py"]
# 设置入口点
ENTRYPOINT ["python"]
CMD ["run.py"]

View File

@ -14,6 +14,7 @@ services:
# 持久化数据和日志
- cryptoai_data:/app/cryptoai/data
- cryptoai_logs:/app/logs
command: python run.py
volumes:
cryptoai_data: