From 749de829d5bad6a05ebe1a733a6bd942c1a386ec Mon Sep 17 00:00:00 2001 From: Ivan Gabaldon Date: Fri, 16 May 2025 11:16:41 +0200 Subject: [mod] container: refactor entrypoint script That entrypoint is prone to screw things up, especially with permission handling. The new script handles initialization better and fixes some issues like delayed settings update via ENVs and timestamp overwriting, also adjusts what should be copied into the container. Related https://github.com/searxng/searxng/pull/4721#issuecomment-2850272129 --- Makefile | 2 +- container/Dockerfile | 11 ++- container/config/uwsgi.ini | 55 ++++++++++++ container/docker-entrypoint.sh | 127 ---------------------------- container/entrypoint.sh | 166 +++++++++++++++++++++++++++++++++++++ container/legacy/Dockerfile | 13 +-- container/uwsgi.ini | 55 ------------ docs/admin/installation-docker.rst | 4 +- utils/lib_sxng_container.sh | 3 +- 9 files changed, 240 insertions(+), 196 deletions(-) create mode 100644 container/config/uwsgi.ini delete mode 100755 container/docker-entrypoint.sh create mode 100755 container/entrypoint.sh delete mode 100644 container/uwsgi.ini diff --git a/Makefile b/Makefile index 917d3aeb4..a7a1535af 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ ci.test: test.yamllint test.black test.types.ci test.pylint test.unit test.robo test: test.yamllint test.black test.types.dev test.pylint test.unit test.robot test.rst test.shell test.shell: $(Q)shellcheck -x -s dash \ - container/docker-entrypoint.sh + container/entrypoint.sh $(Q)shellcheck -x -s bash \ utils/brand.sh \ $(MTOOLS) \ diff --git a/container/Dockerfile b/container/Dockerfile index 0c3b1b1c7..d7bc83802 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -10,11 +10,9 @@ RUN --mount=type=cache,id=pip,target=/root/.cache/pip python -m venv ./venv \ COPY ./searx/ ./searx/ ARG TIMESTAMP_SETTINGS="0" -ARG TIMESTAMP_UWSGI="0" RUN python -m compileall -q searx \ && touch -c --date=@$TIMESTAMP_SETTINGS ./searx/settings.yml \ - && touch -c --date=@$TIMESTAMP_UWSGI ./container/uwsgi.ini \ && find ./searx/static \ \( -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 {} + @@ -29,7 +27,12 @@ ARG LABEL_VCS_URL="unspecified" COPY --chown=searxng:searxng --from=builder /usr/local/searxng/venv/ ./venv/ COPY --chown=searxng:searxng --from=builder /usr/local/searxng/searx/ ./searx/ -COPY --chown=searxng:searxng ./container/ ./container/ +COPY --chown=searxng:searxng ./container/config/ ./.template/ +COPY --chown=searxng:searxng ./container/entrypoint.sh ./entrypoint.sh + +ARG TIMESTAMP_UWSGI="0" + +RUN touch -c --date=@$TIMESTAMP_UWSGI ./.template/uwsgi.ini LABEL org.opencontainers.image.authors="searxng <$GIT_URL>" \ org.opencontainers.image.created="$LABEL_DATE" \ @@ -59,4 +62,4 @@ EXPOSE 8080 HEALTHCHECK CMD wget --quiet --tries=1 --spider http://localhost:8080/healthz || exit 1 -ENTRYPOINT ["/usr/local/searxng/container/docker-entrypoint.sh"] +ENTRYPOINT ["/usr/local/searxng/entrypoint.sh"] diff --git a/container/config/uwsgi.ini b/container/config/uwsgi.ini new file mode 100644 index 000000000..3bfd49e72 --- /dev/null +++ b/container/config/uwsgi.ini @@ -0,0 +1,55 @@ +[uwsgi] +# Listening address +# default value: [::]:8080 (see Dockerfile) +http-socket = $(BIND_ADDRESS) + +# Who will run the code +uid = searxng +gid = searxng + +# Number of workers (usually CPU count) +# default value: %k (= number of CPU core, see Dockerfile) +workers = $(UWSGI_WORKERS) + +# Number of threads per worker +# default value: 4 (see Dockerfile) +threads = $(UWSGI_THREADS) + +# The right granted on the created socket +chmod-socket = 666 + +# Plugin to use and interpreter config +single-interpreter = true +master = true +lazy-apps = true +enable-threads = true + +# Module to import +module = searx.webapp + +# Virtualenv and python path +pythonpath = /usr/local/searxng/ +chdir = /usr/local/searxng/searx/ + +# automatically set processes name to something meaningful +auto-procname = true + +# Disable request logging for privacy +disable-logging = true +log-5xx = true + +# Set the max size of a request (request-body excluded) +buffer-size = 8192 + +# No keep alive +# See https://github.com/searx/searx-docker/issues/24 +add-header = Connection: close + +# Follow SIGTERM convention +# See https://github.com/searxng/searxng/issues/3427 +die-on-term + +# uwsgi serves the static files +static-map = /static=/usr/local/searxng/searx/static +static-gzip-all = True +offload-threads = %k diff --git a/container/docker-entrypoint.sh b/container/docker-entrypoint.sh deleted file mode 100755 index c31040f0f..000000000 --- a/container/docker-entrypoint.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!/bin/sh - -help() { - cat <`__. In the :origin:`Dockerfile` the ENTRYPOINT_ is defined as -:origin:`container/docker-entrypoint.sh` +:origin:`container/entrypoint.sh` .. code:: sh docker run --rm -it searxng/searxng -h -.. program-output:: ../container/docker-entrypoint.sh -h +.. program-output:: ../container/entrypoint.sh -h diff --git a/utils/lib_sxng_container.sh b/utils/lib_sxng_container.sh index 6e29a3809..fd0d072e2 100644 --- a/utils/lib_sxng_container.sh +++ b/utils/lib_sxng_container.sh @@ -114,7 +114,6 @@ container.build() { # shellcheck disable=SC2086 "$container_engine" $params_build_builder \ --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 -- ./container/uwsgi.ini)" \ --tag="localhost/$CONTAINER_IMAGE_ORGANIZATION/$CONTAINER_IMAGE_NAME:builder" \ --file="./container/$dockerfile" \ . @@ -122,6 +121,8 @@ container.build() { # shellcheck disable=SC2086 "$container_engine" $params_build \ + --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 -- ./container/config/uwsgi.ini)" \ --build-arg="GIT_URL=$GIT_URL" \ --build-arg="SEARXNG_GIT_VERSION=$VERSION_STRING" \ --build-arg="LABEL_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ -- cgit v1.2.3