From 749de829d5bad6a05ebe1a733a6bd942c1a386ec Mon Sep 17 00:00:00 2001 From: Ivan Gabaldon Date: Fri, 16 May 2025 11:16:41 +0200 Subject: [PATCH] [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 | 0 container/docker-entrypoint.sh | 127 ---------------------- container/entrypoint.sh | 166 +++++++++++++++++++++++++++++ container/legacy/Dockerfile | 13 +-- docs/admin/installation-docker.rst | 4 +- utils/lib_sxng_container.sh | 3 +- 8 files changed, 185 insertions(+), 141 deletions(-) rename container/{ => config}/uwsgi.ini (100%) delete mode 100755 container/docker-entrypoint.sh create mode 100755 container/entrypoint.sh 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/uwsgi.ini b/container/config/uwsgi.ini similarity index 100% rename from container/uwsgi.ini rename to container/config/uwsgi.ini 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)" \