33 lines
1016 B
Docker
33 lines
1016 B
Docker
|
FROM python:3.11-slim
|
||
|
|
||
|
WORKDIR /app
|
||
|
|
||
|
# 设置国内 pip 镜像
|
||
|
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||
|
|
||
|
# 复制依赖并安装
|
||
|
COPY requirements.txt .
|
||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||
|
|
||
|
# 复制项目
|
||
|
COPY . .
|
||
|
|
||
|
# 暴露端口
|
||
|
EXPOSE 8000
|
||
|
|
||
|
# 设置默认环境变量
|
||
|
ENV CELERY_BROKER_URL=${CELERY_BROKER_URL:-redis://redis:6379/0}
|
||
|
ENV CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND:-redis://redis:6379/0}
|
||
|
ENV CRAWL_API_URL=${CRAWL_API_URL:-http://47.83.141.164:5001/crawl}
|
||
|
|
||
|
# 在构建时替换 settings.py 中的配置
|
||
|
RUN sed -i "s#CELERY_BROKER_URL = .*#CELERY_BROKER_URL = '${CELERY_BROKER_URL}'#" selenium_django/settings.py && \
|
||
|
sed -i "s#CELERY_RESULT_BACKEND = .*#CELERY_RESULT_BACKEND = '${CELERY_RESULT_BACKEND}'#" selenium_django/settings.py && \
|
||
|
sed -i "s#CRAWL_API_URL = .*#CRAWL_API_URL = '${CRAWL_API_URL}'#" selenium_django/settings.py
|
||
|
|
||
|
# 入口脚本
|
||
|
COPY entrypoint.sh /entrypoint.sh
|
||
|
RUN chmod +x /entrypoint.sh
|
||
|
|
||
|
CMD ["/entrypoint.sh"]
|