mirror of
https://github.com/searxng/searxng.git
synced 2025-07-30 00:22:40 +02:00
[mod] make run: start granian server and versioning by Dependabot (#5037)
The new ``requirements-server.txt`` (granian) is installed into the virtualenv of Dockerfile. When ``make run`` is called, a granian server is started with auto reload on application's files changes / requires granian[reload] extra, see ``requirements-dev.txt``. Dependabot supports updates to any ``.txt`` file [1]. [1] https://docs.github.com/en/code-security/dependabot/ecosystems-supported-by-dependabot/supported-ecosystems-and-repositories#pip-and-pip-compile Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
83adda8567
commit
168fa9b09b
5 changed files with 18 additions and 49 deletions
|
@ -1,11 +1,11 @@
|
|||
FROM ghcr.io/searxng/base:searxng-builder AS builder
|
||||
|
||||
COPY ./requirements.txt ./requirements.txt
|
||||
COPY ./requirements*.txt ./
|
||||
|
||||
RUN --mount=type=cache,id=pip,target=/root/.cache/pip python -m venv ./venv \
|
||||
&& . ./venv/bin/activate \
|
||||
&& pip install -r requirements.txt \
|
||||
&& pip install "granian~=2.0"
|
||||
&& pip install -r requirements-server.txt
|
||||
|
||||
COPY ./searx/ ./searx/
|
||||
|
||||
|
|
15
manage
15
manage
|
@ -126,7 +126,20 @@ webapp.run() {
|
|||
sleep 3
|
||||
xdg-open http://127.0.0.1:8888/
|
||||
)&
|
||||
SEARXNG_DEBUG=1 pyenv.cmd python -m searx.webapp
|
||||
SEARXNG_DEBUG=1 \
|
||||
GRANIAN_RELOAD="true" \
|
||||
GRANIAN_RELOAD_IGNORE_WORKER_FAILURE="true" \
|
||||
GRANIAN_RELOAD_PATHS="./searx" \
|
||||
GRANIAN_PROCESS_NAME="searxng" \
|
||||
GRANIAN_INTERFACE="wsgi" \
|
||||
GRANIAN_HOST="::" \
|
||||
GRANIAN_PORT="8888" \
|
||||
GRANIAN_WEBSOCKETS="false" \
|
||||
GRANIAN_LOOP="uvloop" \
|
||||
GRANIAN_BLOCKING_THREADS="4" \
|
||||
GRANIAN_WORKERS_KILL_TIMEOUT="30" \
|
||||
GRANIAN_BLOCKING_THREADS_IDLE_TIMEOUT="300" \
|
||||
pyenv.cmd granian searx.webapp:app
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2119
|
||||
|
|
|
@ -21,3 +21,4 @@ wlc==1.15
|
|||
coloredlogs==15.0.1
|
||||
docutils>=0.21.2
|
||||
parameterized==0.9.0
|
||||
granian[reload]==2.4.2
|
||||
|
|
1
requirements-server.txt
Normal file
1
requirements-server.txt
Normal file
|
@ -0,0 +1 @@
|
|||
granian==2.4.2
|
|
@ -6,7 +6,6 @@
|
|||
# pylint: disable=use-dict-literal
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
@ -28,8 +27,6 @@ from pygments import highlight
|
|||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.formatters import HtmlFormatter # pylint: disable=no-name-in-module
|
||||
|
||||
from werkzeug.serving import is_running_from_reloader
|
||||
|
||||
from whitenoise import WhiteNoise
|
||||
from whitenoise.base import Headers
|
||||
|
||||
|
@ -1364,38 +1361,6 @@ def run():
|
|||
app.run(port=port, host=host, threaded=True)
|
||||
|
||||
|
||||
def is_werkzeug_reload_active() -> bool:
|
||||
"""Returns ``True`` if server is is launched by :ref:`werkzeug.serving` and
|
||||
the ``use_reload`` argument was set to ``True``. If this is the case, it
|
||||
should be avoided that the server is initialized twice (:py:obj:`init`,
|
||||
:py:obj:`run`).
|
||||
|
||||
.. _werkzeug.serving:
|
||||
https://werkzeug.palletsprojects.com/en/stable/serving/#werkzeug.serving.run_simple
|
||||
"""
|
||||
logger.debug("sys.argv: %s", sys.argv)
|
||||
if "uwsgi" in sys.argv[0] or "granian" in sys.argv[0]:
|
||||
# server was launched by granian (or uWSGI)
|
||||
return False
|
||||
|
||||
# https://github.com/searxng/searxng/pull/1656#issuecomment-1214198941
|
||||
# https://github.com/searxng/searxng/pull/1616#issuecomment-1206137468
|
||||
|
||||
frames = inspect.stack()
|
||||
|
||||
if len(frames) > 1 and frames[-2].filename.endswith('flask/cli.py'):
|
||||
# server was launched by "flask run", is argument "--reload" set?
|
||||
if "--reload" in sys.argv or "--debug" in sys.argv:
|
||||
return True
|
||||
|
||||
elif frames[0].filename.endswith('searx/webapp.py'):
|
||||
# server was launched by "python -m searx.webapp" / see run()
|
||||
if searx.sxng_debug:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def init():
|
||||
|
||||
if searx.sxng_debug or app.debug:
|
||||
|
@ -1408,17 +1373,6 @@ def init():
|
|||
logger.error("server.secret_key is not changed. Please use something else instead of ultrasecretkey.")
|
||||
sys.exit(1)
|
||||
|
||||
# When automatic reloading is activated stop Flask from initialising twice.
|
||||
# - https://github.com/pallets/flask/issues/5307#issuecomment-1774646119
|
||||
# - https://stackoverflow.com/a/25504196
|
||||
|
||||
reloader_active = is_werkzeug_reload_active()
|
||||
werkzeug_run_main = is_running_from_reloader()
|
||||
|
||||
if reloader_active and not werkzeug_run_main:
|
||||
logger.info("in reloading mode and not in main loop, cancel the initialization")
|
||||
return
|
||||
|
||||
locales_initialize()
|
||||
valkey_initialize()
|
||||
searx.plugins.initialize(app)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue