From 4b43775c91a3c2ef415527edb4b3c041859453b4 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 27 Jul 2021 18:37:46 +0200 Subject: [PATCH] version based on the git repository This commit remove the need to update the brand for GIT_URL and GIT_BRANCH: there are read from the git repository. It is possible to call python -m searx.version freeze to freeze the current version. Useful when the code is installed outside git (distro package, docker, etc...) --- Dockerfile | 3 - docs/conf.py | 4 +- docs/dev/makefile.rst | 4 +- manage | 40 ++----- searx/settings.yml | 5 - searx/settings_defaults.py | 2 - searx/templates/__common__/about.html | 8 +- searx/templates/oscar/base.html | 2 +- searx/templates/simple/base.html | 2 +- searx/utils.py | 4 +- searx/version.py | 158 ++++++++++++++++++++++---- searx/webapp.py | 5 +- setup.py | 9 +- utils/brand.env | 4 +- utils/build_env.py | 8 +- utils/searx.sh | 39 +++++-- 16 files changed, 199 insertions(+), 98 deletions(-) diff --git a/Dockerfile b/Dockerfile index 13885611b..63f886eba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,9 +60,6 @@ ARG VERSION_GITCOMMIT=unknown RUN su searx -c "/usr/bin/python3 -m compileall -q searx"; \ touch -c --date=@${TIMESTAMP_SETTINGS} searx/settings.yml; \ touch -c --date=@${TIMESTAMP_UWSGI} dockerfiles/uwsgi.ini; \ - if [ ! -z $VERSION_GITCOMMIT ]; then\ - echo "VERSION_STRING = VERSION_STRING + \"-$VERSION_GITCOMMIT\"" >> /usr/local/searx/searx/version.py; \ - fi; \ find /usr/local/searx/searx/static -a \( -name '*.html' -o -name '*.css' -o -name '*.js' \ -o -name '*.svg' -o -name '*.ttf' -o -name '*.eot' \) \ -type f -exec gzip -9 -k {} \+ -exec brotli --best {} \+ diff --git a/docs/conf.py b/docs/conf.py index 04c8aa205..978d6a660 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,7 +5,7 @@ import sys, os from pallets_sphinx_themes import ProjectLink from searx import get_setting -from searx.version import VERSION_STRING +from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH # Project -------------------------------------------------------------- @@ -15,8 +15,6 @@ author = u'Adam Tauber' release, version = VERSION_STRING, VERSION_STRING SEARX_URL = get_setting('server.base_url') or 'https://example.org/searx' -GIT_URL = get_setting('brand.git_url') -GIT_BRANCH = get_setting('brand.git_branch') ISSUE_URL = get_setting('brand.issue_url') DOCS_URL = get_setting('brand.docs_url') PUBLIC_INSTANCES = get_setting('brand.public_instances') diff --git a/docs/dev/makefile.rst b/docs/dev/makefile.rst index 5bf3c13b2..0b5af3cd8 100644 --- a/docs/dev/makefile.rst +++ b/docs/dev/makefile.rst @@ -107,8 +107,8 @@ The ``make buildenv`` target will update the *build environment* in: Tasks running outside of an *installed instance*, need the following settings from the YAML configuration: -- ``GIT_URL`` from :ref:`brand.git_url ` -- ``GIT_BRANCH`` from :ref:`brand.git_branch ` +- ``GIT_URL`` from git configuration +- ``GIT_BRANCH`` from git configuration - ``SEARX_URL`` from :ref:`server.base_url ` (aka ``PUBLIC_URL``) diff --git a/manage b/manage index b974c3028..04de3ee59 100755 --- a/manage +++ b/manage @@ -115,8 +115,11 @@ buildenv() { fi fi export SEARX_SETTINGS_PATH - SEARX_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \ - | prefix_stdout "${_Blue}BUILDENV${_creset} " + ( + set -e + SEARX_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \ + | prefix_stdout "${_Blue}BUILDENV${_creset} " + ) return "${PIPESTATUS[0]}" } @@ -200,7 +203,6 @@ docker.build() { local SEARX_GIT_VERSION local VERSION_GITCOMMIT - local SEARX_PYTHON_VERSION local GITHUB_USER local SEARX_IMAGE_NAME local BUILD @@ -227,34 +229,14 @@ docker.build() { fi # This is a git repository - - # "git describe" to get the Docker version (for example : v0.15.0-89-g0585788e) - # awk to remove the "v" and the "g" - SEARX_GIT_VERSION=$(git describe --match "v[0-9]*\.[0-9]*\.[0-9]*" HEAD 2>/dev/null | awk -F'-' '{OFS="-"; $1=substr($1, 2); if ($3) { $3=substr($3, 2); } print}') - - # add the suffix "-dirty" if the repository has uncommited change - # /!\ HACK for searx/searx: ignore utils/brand.env git update-index -q --refresh - if [ ! -z "$(git diff-index --name-only HEAD -- | grep -v 'utils/brand.env')" ]; then - SEARX_GIT_VERSION="${SEARX_GIT_VERSION}-dirty" - fi + pyenv.cmd python -m searx.version freeze + eval "$(pyenv.cmd python -m searx.version)" - # Get the last git commit id, will be added to the Searx version (see Dockerfile) - VERSION_GITCOMMIT=$(echo "$SEARX_GIT_VERSION" | cut -d- -f2-4) + # Get the last git commit id + VERSION_GITCOMMIT=$(echo "$VERSION_STRING" | cut -d- -f3) build_msg DOCKER "Last commit : $VERSION_GITCOMMIT" - # Check consistency between the git tag and the searx/version.py file - # /! HACK : parse Python file with bash /! - # otherwise it is not possible build the docker image without all Python - # dependencies ( version.py loads __init__.py ) - # SEARX_PYTHON_VERSION=$(python3 -c "import six; import searx.version; six.print_(searx.version.VERSION_STRING)") - SEARX_PYTHON_VERSION=$(cat searx/version.py | grep "\(VERSION_MAJOR\|VERSION_MINOR\|VERSION_BUILD\) =" | cut -d\= -f2 | sed -e 's/^[[:space:]]*//' | paste -sd "." -) - if [ "$(echo "$SEARX_GIT_VERSION" | cut -d- -f1)" != "$SEARX_PYTHON_VERSION" ]; then - err_msg "git tag: $SEARX_GIT_VERSION" - err_msg "searx/version.py: $SEARX_PYTHON_VERSION" - die 1 "Inconsistency between the last git tag and the searx/version.py file" - fi - # define the docker image name GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/') SEARX_IMAGE_NAME="${SEARX_IMAGE_NAME:-${GITHUB_USER:-searxng}/searxng}" @@ -274,14 +256,14 @@ docker.build() { docker $BUILD \ --build-arg BASE_IMAGE="${DEPENDENCIES_IMAGE_NAME}" \ --build-arg GIT_URL="${GIT_URL}" \ - --build-arg SEARX_GIT_VERSION="${SEARX_GIT_VERSION}" \ + --build-arg SEARX_GIT_VERSION="${VERSION_STRING}" \ --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \ --build-arg LABEL_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ --build-arg LABEL_VCS_REF="$(git rev-parse HEAD)" \ --build-arg LABEL_VCS_URL="${GIT_URL}" \ --build-arg TIMESTAMP_SETTINGS="$(git log -1 --format="%cd" --date=unix -- searx/settings.yml)" \ --build-arg TIMESTAMP_UWSGI="$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini)" \ - -t "${SEARX_IMAGE_NAME}:latest" -t "${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}" . + -t "${SEARX_IMAGE_NAME}:latest" -t "${SEARX_IMAGE_NAME}:${VERSION_STRING}" . if [ "$1" = "push" ]; then docker push "${SEARX_IMAGE_NAME}:latest" diff --git a/searx/settings.yml b/searx/settings.yml index ec8d99d1b..bc7eec802 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -10,11 +10,6 @@ brand: wiki_url: https://github.com/searxng/searxng/wiki issue_url: https://github.com/searxng/searxng/issues - # If you change a value below don't forget to rebuild instance's enviroment - # (make buildenv) - git_url: https://github.com/searxng/searxng - git_branch: master - search: # Filter results. 0: None, 1: Moderate, 2: Strict safe_search: 0 diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 72d7dc588..e3955d97b 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -130,8 +130,6 @@ SCHEMA = { 'contact_url': SettingsValue((None, False, str), None), }, 'brand': { - 'git_url': SettingsValue(str), - 'git_branch': SettingsValue(str), 'issue_url': SettingsValue(str, None), 'new_issue_url': SettingsValue(str, None), 'docs_url': SettingsValue(str, None), diff --git a/searx/templates/__common__/about.html b/searx/templates/__common__/about.html index 96ebab28a..707802d45 100644 --- a/searx/templates/__common__/about.html +++ b/searx/templates/__common__/about.html @@ -11,7 +11,7 @@

More about SearXNG ...

@@ -30,7 +30,7 @@
  • SearXNG is free software, the code is 100% open and you can help to make - it better. See more on SearXNG sources.
  • @@ -81,7 +81,7 @@

    SearXNG appreciates your concern regarding logs, so take the code from - the SearXNG project and + the SearXNG project and run it yourself!

    @@ -95,7 +95,7 @@

    See the SearXNG docs - and SearXNG sources + and SearXNG sources

    diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html index cc716e62b..7cd38a25c 100644 --- a/searx/templates/oscar/base.html +++ b/searx/templates/oscar/base.html @@ -83,7 +83,7 @@

    {{ _('Powered by') }} SearXNG - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}
    - {{ _('Source code') }} | + {{ _('Source code') }} | {{ _('Issue tracker') }} | {{ _('Public instances') }}{% if get_setting('general.contact_url') %} | {{ _('Contact instance maintainer') }}{% endif %} diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html index edf0eb6eb..7020de756 100644 --- a/searx/templates/simple/base.html +++ b/searx/templates/simple/base.html @@ -51,7 +51,7 @@