Dockerfile.base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # 基于官方的 Ubuntu 镜像
  2. FROM debian:stable-slim AS ubuntu-base
  3. # 设置环境变量,避免在安装过程中提示交互式输入
  4. ENV DEBIAN_FRONTEND=noninteractive
  5. # 安装必要的依赖
  6. RUN apt-get update && apt-get install -y \
  7. wget \
  8. bzip2 \
  9. ca-certificates \
  10. && rm -rf /var/lib/apt/lists/*
  11. FROM ubuntu-base AS ubuntu-anaconda
  12. # 下载并安装 Anaconda
  13. RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh -O ~/anaconda.sh && \
  14. /bin/bash ~/anaconda.sh -b -p /opt/conda && \
  15. rm ~/anaconda.sh && \
  16. echo "export PATH=/opt/conda/bin:$PATH" >> ~/.bashrc && \
  17. /opt/conda/bin/conda clean --all -y
  18. ENV PATH="/opt/conda/bin:$PATH"
  19. #设置清华源
  20. FROM ubuntu-anaconda AS ubuntu-anaconda-config
  21. RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ && \
  22. conda config --set show_channel_urls yes
  23. COPY environment.yml /app/environment.yml
  24. RUN apt-get update && \
  25. apt-get install -y python3-dev libpq-dev
  26. RUN apt-get install -y build-essential
  27. RUN conda env create -f /app/environment.yml
  28. RUN apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean && rm -rf /var/lib/apt/lists/*
  29. # 配置 Conda 环境变量
  30. # 创建名为 server 的 Python 虚拟环境
  31. #RUN conda create -y -n server python=3.9 && \
  32. # conda clean --all -y
  33. # 将 requirements.txt 文件复制到镜像中
  34. #COPY requirements.txt /app/requirements.txt
  35. # 激活 server 环境并使用 pip 安装依赖库
  36. # RUN conda run -n server pip install --no-cache-dir -r /app/requirements.txt
  37. # 将 FastAPI 应用代码复制到镜像中
  38. FROM ubuntu-anaconda-config AS ubuntu-anaconda-app
  39. COPY . /app
  40. # 设置环境变量(这些环境变量可以在容器启动时覆盖)
  41. ENV POSTGRESQL_HOST="localhost"
  42. ENV POSTGRESQL_DATABASE="kg"
  43. ENV POSTGRESQL_USER="postgres"
  44. #ENV POSTGRESQL_PASSWORD="difyai123456"
  45. ENV DEEPSEEK_API_URL="https://api.siliconflow.cn/v1/chat/completions"
  46. #ENV DEEPSEEK_API_KEY="sk-vecnpjmtmelcefdbtbbpqvzcegopxrherbnbjhscugbpxuif"
  47. ENV JOB_PATH="/app/agent/jobs"
  48. ENV JOB_SCRIPT_PATH="/app/agent/job_script"
  49. # 创建日志目录
  50. RUN mkdir -p /app/logs
  51. # 创建一个启动脚本
  52. RUN echo '#!/bin/bash' > /start.sh && \
  53. echo 'source /opt/conda/etc/profile.d/conda.sh' >> /start.sh && \
  54. echo 'conda activate kgbuilder' >> /start.sh && \
  55. echo 'cd /app' >> /start.sh && \
  56. echo 'python agent/main.py' >> /start.sh && \
  57. chmod +x /start.sh
  58. # 设置默认命令
  59. CMD ["/bin/bash", "/start.sh"]