优化 Dockerfile

This commit is contained in:
2025-11-10 17:14:15 +08:00
parent 428b5762d2
commit f8ed0ef3c0
3 changed files with 87 additions and 29 deletions

View File

@@ -13,29 +13,8 @@ USER root
WORKDIR /ragflow WORKDIR /ragflow
# Set UV HTTP timeout to handle large package downloads (e.g., nvidia-cusolver-cu12) # Python dependencies are already installed in base image
# Default is 30s, increase to 600s (10 minutes) for large packages # Build web application
ENV UV_HTTP_TIMEOUT=600
# install dependencies from pyproject.toml
COPY pyproject.toml ./
# https://github.com/astral-sh/uv/issues/10462
# uv records index url into uv.lock but doesn't failover among multiple indexes
# Generate uv.lock from pyproject.toml and install dependencies with cache
RUN --mount=type=cache,id=ragflow_uv,target=/root/.cache/uv,sharing=locked \
if [ "$NEED_MIRROR" == "1" ]; then \
uv lock --index-url https://mirrors.aliyun.com/pypi/simple; \
sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' uv.lock; \
else \
uv lock; \
sed -i 's|mirrors.aliyun.com/pypi|pypi.org|g' uv.lock; \
fi; \
if [ "$LIGHTEN" == "1" ]; then \
uv sync --python 3.10 --frozen; \
else \
uv sync --python 3.10 --frozen --all-extras; \
fi
COPY web web COPY web web
COPY docs docs COPY docs docs
RUN --mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked \ RUN --mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked \
@@ -58,11 +37,7 @@ USER root
WORKDIR /ragflow WORKDIR /ragflow
# Copy Python environment and packages # Python environment is already set up in base image
ENV VIRTUAL_ENV=/ragflow/.venv
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
ENV PYTHONPATH=/ragflow/ ENV PYTHONPATH=/ragflow/
COPY web web COPY web web

View File

@@ -137,3 +137,31 @@ RUN --mount=type=bind,from=infiniflow/ragflow_deps:latest,source=/,target=/deps
dpkg -i /deps/libssl1.1_1.1.1f-1ubuntu2_arm64.deb; \ dpkg -i /deps/libssl1.1_1.1.1f-1ubuntu2_arm64.deb; \
fi fi
# Install Python dependencies from pyproject.toml
# This is done in base image since dependencies don't change frequently
COPY pyproject.toml ./
# https://github.com/astral-sh/uv/issues/10462
# uv records index url into uv.lock but doesn't failover among multiple indexes
# Generate uv.lock from pyproject.toml and install dependencies with cache
# Set UV HTTP timeout based on mirror usage:
# - With mirror (NEED_MIRROR=1): 600s for potentially slower mirror connections
# - Without mirror (abroad): 300s should be sufficient for PyPI with good network
RUN --mount=type=cache,id=ragflow_uv,target=/root/.cache/uv,sharing=locked \
export UV_HTTP_TIMEOUT=$([ "$NEED_MIRROR" == "1" ] && echo "600" || echo "300") && \
if [ "$NEED_MIRROR" == "1" ]; then \
uv lock --index-url https://mirrors.aliyun.com/pypi/simple; \
sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' uv.lock; \
else \
uv lock; \
sed -i 's|mirrors.aliyun.com/pypi|pypi.org|g' uv.lock; \
fi && \
if [ "$LIGHTEN" == "1" ]; then \
uv sync --python 3.10 --frozen; \
else \
uv sync --python 3.10 --frozen --all-extras; \
fi
# Set Python environment variables
ENV VIRTUAL_ENV=/ragflow/.venv
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

View File

@@ -4,7 +4,7 @@ services:
container_name: ragflow-opensearch-01 container_name: ragflow-opensearch-01
profiles: profiles:
- opensearch - opensearch
image: hub.icert.top/opensearchproject/opensearch:2.19.1 image: hub.icert.top/opensearchproject/opensearch:3.3.2
volumes: volumes:
- osdata01:/usr/share/opensearch/data - osdata01:/usr/share/opensearch/data
ports: ports:
@@ -38,6 +38,61 @@ services:
- ragflow - ragflow
restart: on-failure restart: on-failure
opensearch-dashboards:
container_name: ragflow-opensearch-dashboards
profiles:
- opensearch
image: opensearchproject/opensearch-dashboards:3.3.0
env_file: .env
environment:
- OPENSEARCH_HOSTS=["http://opensearch01:9201"]
- OPENSEARCH_USERNAME=admin
- OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
- TZ=${TIMEZONE}
ports:
- 5601:5601
depends_on:
- opensearch01
networks:
- ragflow
restart: on-failure
es01:
container_name: ragflow-es-01
profiles:
- elasticsearch
image: elasticsearch:${STACK_VERSION}
volumes:
- esdata01:/usr/share/elasticsearch/data
ports:
- ${ES_PORT}:9200
env_file: .env
environment:
- node.name=es01
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=false
- discovery.type=single-node
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=false
- xpack.security.transport.ssl.enabled=false
- cluster.routing.allocation.disk.watermark.low=5gb
- cluster.routing.allocation.disk.watermark.high=3gb
- cluster.routing.allocation.disk.watermark.flood_stage=2gb
- TZ=${TIMEZONE}
mem_limit: ${MEM_LIMIT}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test: ["CMD-SHELL", "curl http://localhost:9200"]
interval: 10s
timeout: 10s
retries: 120
networks:
- ragflow
restart: on-failure
postgres: postgres:
image: postgres:15 image: postgres:15