Print version when RAGFlow server startup (#3393)

### What problem does this PR solve?

Print version when RAGFlow server startup

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Signed-off-by: jinhai <haijin.chn@gmail.com>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
Jin Hai
2024-11-14 15:51:30 +08:00
committed by GitHub
parent 95d21e5d9f
commit 201bbef7c0
6 changed files with 97 additions and 6 deletions

View File

@ -35,7 +35,7 @@ from api.utils.log_utils import logger
from api.db.db_models import init_database_tables as init_web_db
from api.db.init_data import init_web_data
from api.versions import get_versions
from api.versions import get_versions, RAGFLOW_VERSION_INFO
def update_progress():
@ -56,6 +56,9 @@ if __name__ == '__main__':
/_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
""")
logger.info(
f'RAGFlow version: {RAGFLOW_VERSION_INFO}'
)
logger.info(
f'project base: {utils.file_utils.get_project_base_directory()}'
)

View File

@ -15,6 +15,7 @@
#
import dotenv
import typing
import subprocess
def get_versions() -> typing.Mapping[str, typing.Any]:
@ -23,4 +24,29 @@ def get_versions() -> typing.Mapping[str, typing.Any]:
def get_rag_version() -> typing.Optional[str]:
return get_versions().get("RAGFLOW_IMAGE", "infiniflow/ragflow:dev").split(":")[-1]
return get_versions().get("RAGFLOW_IMAGE", "infiniflow/ragflow:dev").split(":")[-1]
RAGFLOW_VERSION_INFO = "dev"
def get_closest_tag_and_count():
# Get the current commit hash
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')
# Get the commit count since the closest tag
process = subprocess.Popen(['git', 'rev-list', '--count', f'{closest_tag}..HEAD'], stdout=subprocess.PIPE)
commits_count, _ = process.communicate()
commits_count = int(commits_count.strip())
if commits_count == 0:
return closest_tag
else:
return f"{commit_id}({closest_tag}~{commits_count})"
if RAGFLOW_VERSION_INFO == 'dev':
RAGFLOW_VERSION_INFO = get_closest_tag_and_count()