From e042d67e8d1e29373d03e65ea01f713392b31379 Mon Sep 17 00:00:00 2001 From: Zhichang Yu Date: Wed, 20 Nov 2024 22:33:14 +0800 Subject: [PATCH] Introduced VERSION file --- Dockerfile | 19 +++++++++++++++++-- Dockerfile.slim | 25 +++++++++++++++++++++++-- api/versions.py | 49 +++++++++++++++++++++++++++++++++++-------------- docker/.env | 2 +- web/.umirc.ts | 2 +- 5 files changed, 77 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec5b1dad9a..deff8fb5a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ # base stage FROM ubuntu:22.04 AS base USER root +SHELL ["/bin/bash", "-c"] ENV LIGHTEN=0 @@ -60,7 +61,21 @@ WORKDIR /ragflow COPY .git /ragflow/.git -RUN git --git-dir=/ragflow/.git describe --tags --abbrev=0 > /ragflow/VERSION +RUN current_commit=$(git rev-parse --short HEAD); \ + last_tag=$(git describe --tags --abbrev=0); \ + commit_count=$(git rev-list --count "$last_tag..HEAD"); \ + version_info=""; \ + if [ "$commit_count" -eq 0 ]; then \ + version_info=$last_tag; \ + else \ + version_info="$current_commit($last_tag~$commit_count)"; \ + fi; \ + if [ "$LIGHTEN" == "1" ]; then \ + version_info="$version_info slim"; \ + else \ + version_info="$version_info full"; \ + fi; \ + echo $version_info > /ragflow/VERSION COPY web web COPY docs docs @@ -71,7 +86,7 @@ RUN --mount=type=cache,id=ragflow_builder_npm,target=/root/.npm,sharing=locked \ COPY pyproject.toml poetry.toml poetry.lock ./ RUN --mount=type=cache,id=ragflow_builder_poetry,target=/root/.cache/pypoetry,sharing=locked \ - if [ "$LIGHTEN" -eq 0 ]; then \ + if [ "$LIGHTEN" == "0" ]; then \ poetry install --no-root --with=full; \ else \ poetry install --no-root; \ diff --git a/Dockerfile.slim b/Dockerfile.slim index da3c280e4b..e4ea223cd1 100644 --- a/Dockerfile.slim +++ b/Dockerfile.slim @@ -1,6 +1,7 @@ # base stage FROM ubuntu:22.04 AS base USER root +SHELL ["/bin/bash", "-c"] ENV LIGHTEN=1 @@ -17,7 +18,7 @@ RUN sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' RUN --mount=type=cache,id=ragflow_base_apt,target=/var/cache/apt,sharing=locked \ apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl libpython3-dev nginx libglib2.0-0 libglx-mesa0 pkg-config libicu-dev libgdiplus default-jdk python3-pip pipx \ - libatk-bridge2.0-0 libgtk-4-1 libnss3 xdg-utils unzip libgbm-dev wget \ + libatk-bridge2.0-0 libgtk-4-1 libnss3 xdg-utils unzip libgbm-dev wget git \ && rm -rf /var/lib/apt/lists/* RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && pip3 config set global.trusted-host "pypi.tuna.tsinghua.edu.cn mirrors.pku.edu.cn" && pip3 config set global.extra-index-url "https://mirrors.pku.edu.cn/pypi/web/simple" \ @@ -58,6 +59,24 @@ USER root WORKDIR /ragflow +COPY .git /ragflow/.git + +RUN current_commit=$(git rev-parse --short HEAD); \ + last_tag=$(git describe --tags --abbrev=0); \ + commit_count=$(git rev-list --count "$last_tag..HEAD"); \ + version_info=""; \ + if [ "$commit_count" -eq 0 ]; then \ + version_info=$last_tag; \ + else \ + version_info="$current_commit($last_tag~$commit_count)"; \ + fi; \ + if [ "$LIGHTEN" == "1" ]; then \ + version_info="$version_info slim"; \ + else \ + version_info="$version_info full"; \ + fi; \ + echo $version_info > /ragflow/VERSION + COPY web web COPY docs docs RUN --mount=type=cache,id=ragflow_builder_npm,target=/root/.npm,sharing=locked \ @@ -67,7 +86,7 @@ RUN --mount=type=cache,id=ragflow_builder_npm,target=/root/.npm,sharing=locked \ COPY pyproject.toml poetry.toml poetry.lock ./ RUN --mount=type=cache,id=ragflow_builder_poetry,target=/root/.cache/pypoetry,sharing=locked \ - if [ "$LIGHTEN" -eq 0 ]; then \ + if [ "$LIGHTEN" == "0" ]; then \ poetry install --no-root --with=full; \ else \ poetry install --no-root; \ @@ -79,6 +98,8 @@ USER root WORKDIR /ragflow +COPY --from=builder /ragflow/VERSION /ragflow/VERSION + # Install python packages' dependencies # cv2 requires libGL.so.1 RUN --mount=type=cache,id=ragflow_production_apt,target=/var/cache/apt,sharing=locked \ diff --git a/api/versions.py b/api/versions.py index a528734835..46f6faf285 100644 --- a/api/versions.py +++ b/api/versions.py @@ -13,26 +13,51 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +import os import subprocess -def get_ragflow_version() -> str: - return RAGFLOW_VERSION_INFO +RAGFLOW_VERSION_INFO = "unknown" -RAGFLOW_VERSION_INFO = "dev" +def get_ragflow_version() -> str: + global RAGFLOW_VERSION_INFO + if RAGFLOW_VERSION_INFO != "unknown": + return RAGFLOW_VERSION_INFO + version_path = os.path.abspath( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), os.pardir, "VERSION" + ) + ) + if os.path.exists(version_path): + with open(version_path, "r") as f: + RAGFLOW_VERSION_INFO = f.read().strip() + else: + RAGFLOW_VERSION_INFO = get_closest_tag_and_count() + LIGHTEN = int(os.environ.get("LIGHTEN", "0")) + RAGFLOW_VERSION_INFO += " slim" if LIGHTEN == 1 else " full" + return RAGFLOW_VERSION_INFO def get_closest_tag_and_count(): try: # Get the current commit hash - commit_id = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8') + commit_id = ( + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) + .strip() + .decode("utf-8") + ) # Get the closest tag - closest_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8') - # Get the commit hash of the closest tag - closest_tag_commit = subprocess.check_output(['git', 'rev-list', '-n', '1', closest_tag]).strip().decode( - 'utf-8') + closest_tag = ( + subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) + .strip() + .decode("utf-8") + ) # Get the commit count since the closest tag - process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE) + process = subprocess.Popen( + ["git", "rev-list", "--count", f"{closest_tag}..HEAD"], + stdout=subprocess.PIPE, + ) commits_count, _ = process.communicate() commits_count = int(commits_count.strip()) @@ -41,8 +66,4 @@ def get_closest_tag_and_count(): else: return f"{commit_id}({closest_tag}~{commits_count})" except Exception: - return 'unknown' - - -if RAGFLOW_VERSION_INFO == 'dev': - RAGFLOW_VERSION_INFO = get_closest_tag_and_count() + return "unknown" diff --git a/docker/.env b/docker/.env index 973178fb14..863e5d2bcc 100644 --- a/docker/.env +++ b/docker/.env @@ -81,7 +81,7 @@ SVR_HTTP_PORT=9380 # The RAGFlow Docker image to download. # Defaults to the dev-slim edition, which is the RAGFlow Docker image without embedding models. -RAGFLOW_IMAGE=infiniflow/ragflow:dev +RAGFLOW_IMAGE=infiniflow/ragflow:dev-slim # # To download the RAGFlow Docker image with embedding models, uncomment the following line instead: # RAGFLOW_IMAGE=infiniflow/ragflow:dev diff --git a/web/.umirc.ts b/web/.umirc.ts index b96d84c1bb..8de9ff1e15 100644 --- a/web/.umirc.ts +++ b/web/.umirc.ts @@ -34,7 +34,7 @@ export default defineConfig({ proxy: [ { context: ['/api', '/v1'], - target: 'http://127.0.0.1:9380/', + target: 'http://127.0.0.1:9456/', changeOrigin: true, ws: true, logger: console,