From 3afd9492681cd98eef2db1ce5e1f0a3b7147381a Mon Sep 17 00:00:00 2001 From: Ivan Gabaldon Date: Sat, 17 Oct 2026 20:30:09 +0200 Subject: [PATCH] [enh] container: merge dockerfiles (#6861) * [enh] container: merge dockerfiles Leftover from https://github.com/searxng/searxng/pull/6720 * [enh] apply suggestion https://github.com/searxng/searxng/pull/6861#discussion_r4302473383 --- container/{dist.dockerfile => Dockerfile} | 30 +++++++++++++++++++++-- container/builder.dockerfile | 25 ------------------- docs/admin/installation-docker.rst | 12 ++++----- utils/lib_sxng_container.sh | 13 ++-------- 4 files changed, 36 insertions(+), 44 deletions(-) rename container/{dist.dockerfile => Dockerfile} (56%) delete mode 100644 container/builder.dockerfile diff --git a/container/dist.dockerfile b/container/Dockerfile similarity index 56% rename from container/dist.dockerfile rename to container/Dockerfile index b5766428f..ee60aa379 100644 --- a/container/dist.dockerfile +++ b/container/Dockerfile @@ -1,4 +1,29 @@ -FROM localhost/searxng/searxng:builder AS builder +FROM docker.io/searxng/base:searxng-builder AS builder + +COPY ./requirements.txt ./requirements-server.txt ./ + +ENV UV_NO_MANAGED_PYTHON="true" + +RUN --mount=type=cache,id=uv,target=/root/.cache/uv set -eux -o pipefail; \ + uv venv; \ + uv pip install --requirements ./requirements.txt --requirements ./requirements-server.txt; \ + uv cache prune --ci; \ + find ./.venv/lib/ -type f -exec strip --strip-unneeded {} + || true; \ + find ./.venv/lib/ -type d -name "__pycache__" -exec rm -rf {} +; \ + find ./.venv/lib/ -type f -name "*.pyc" -delete; \ + python -m compileall -q -f -j 0 --invalidation-mode=unchecked-hash ./.venv/lib/ + +COPY --exclude=./searx/version_frozen.py ./searx/ ./searx/ + +RUN set -eux -o pipefail; \ + python -m compileall -q -f -j 0 --invalidation-mode=unchecked-hash ./searx/; \ + find ./searx/static/ -type f \ + \( -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.svg" \) \ + -exec gzip -9 -k {} + \ + -exec brotli -9 -k {} + \ + -exec gzip --test {}.gz + \ + -exec brotli --test {}.br + + FROM docker.io/searxng/base:searxng AS dist COPY --chown=977:977 --from=builder /usr/local/searxng/.venv/ ./.venv/ @@ -21,6 +46,8 @@ LABEL org.opencontainers.image.created="$CREATED" \ org.opencontainers.image.url="https://searxng.org" \ org.opencontainers.image.version="$VERSION" +# Extended from: +# https://codeberg.org/searxng/base/src/branch/main/Dockerfile ENV __SEARXNG_VERSION="$VERSION" \ __SEARXNG_SETTINGS_PATH="$__SEARXNG_CONFIG_PATH/settings.yml" \ GRANIAN_PROCESS_NAME="searxng" \ @@ -32,7 +59,6 @@ ENV __SEARXNG_VERSION="$VERSION" \ GRANIAN_WORKERS_KILL_TIMEOUT="30s" \ GRANIAN_BLOCKING_THREADS_IDLE_TIMEOUT="5m" -# "*_PATH" ENVs are defined in base images VOLUME $__SEARXNG_CONFIG_PATH VOLUME $__SEARXNG_DATA_PATH diff --git a/container/builder.dockerfile b/container/builder.dockerfile deleted file mode 100644 index 38ec42f9a..000000000 --- a/container/builder.dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM docker.io/searxng/base:searxng-builder AS builder - -COPY ./requirements.txt ./requirements-server.txt ./ - -ENV UV_NO_MANAGED_PYTHON="true" - -RUN --mount=type=cache,id=uv,target=/root/.cache/uv set -eux -o pipefail; \ - uv venv; \ - uv pip install --requirements ./requirements.txt --requirements ./requirements-server.txt; \ - uv cache prune --ci; \ - find ./.venv/lib/ -type f -exec strip --strip-unneeded {} + || true; \ - find ./.venv/lib/ -type d -name "__pycache__" -exec rm -rf {} +; \ - find ./.venv/lib/ -type f -name "*.pyc" -delete; \ - python -m compileall -q -f -j 0 --invalidation-mode=unchecked-hash ./.venv/lib/ - -COPY --exclude=./searx/version_frozen.py ./searx/ ./searx/ - -RUN set -eux -o pipefail; \ - python -m compileall -q -f -j 0 --invalidation-mode=unchecked-hash ./searx/; \ - find ./searx/static/ -type f \ - \( -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.svg" \) \ - -exec gzip -9 -k {} + \ - -exec brotli -9 -k {} + \ - -exec gzip --test {}.gz + \ - -exec brotli --test {}.br + diff --git a/docs/admin/installation-docker.rst b/docs/admin/installation-docker.rst index 8ffd512bc..92f7efd9f 100644 --- a/docs/admin/installation-docker.rst +++ b/docs/admin/installation-docker.rst @@ -283,12 +283,12 @@ container images are not officially supported): $ make container $ docker images - REPOSITORY TAG IMAGE ID SIZE - localhost/searxng/searxng 2026.6.19-93f66bfb4 ... 265 MB - localhost/searxng/searxng latest ... 265 MB - localhost/searxng/searxng builder ... 687 MB - docker.io/searxng/base searxng-builder ... 565 MB - docker.io/searxng/base searxng ... 143 MB + REPOSITORY TAG IMAGE ID SIZE + localhost/searxng/searxng latest ... 271 MB + localhost/searxng/searxng 2026.10.17-* ... 271 MB + ... 677 MB + docker.io/searxng/base searxng ... 144 MB + docker.io/searxng/base searxng-builder ... 550 MB Migrate from ``searxng-docker`` =============================== diff --git a/utils/lib_sxng_container.sh b/utils/lib_sxng_container.sh index a4a6db8ba..707a2e240 100644 --- a/utils/lib_sxng_container.sh +++ b/utils/lib_sxng_container.sh @@ -126,11 +126,9 @@ container.build() { info_msg "Set \$GIT_URL: $GIT_URL" if [ "$container_engine" = "podman" ]; then - params_build_builder="build --format=oci --layers --platform=$platform --identity-label=false" params_build="build --format=oci --layers --platform=$platform --identity-label=false" else - params_build_builder="build --platform=$platform" - params_build=$params_build_builder + params_build="build --platform=$platform" fi local_tag_arch="localhost/searxng/searxng:$DOCKER_TAG-$arch$variant" @@ -140,20 +138,13 @@ container.build() { params_build+=" --tag=localhost/searxng/searxng:$DOCKER_TAG" fi - # shellcheck disable=SC2086 - "$container_engine" $params_build_builder \ - --tag="localhost/searxng/searxng:builder" \ - --file="./container/builder.dockerfile" \ - . - build_msg CONTAINER "Image \"builder\" built" - # shellcheck disable=SC2086 "$container_engine" $params_build \ --build-arg="CREATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ --build-arg="VERSION=$DOCKER_TAG" \ --build-arg="VCS_URL=$GIT_URL" \ --build-arg="VCS_REVISION=$(git rev-parse HEAD)" \ - --file="./container/dist.dockerfile" \ + --file="./container/Dockerfile" \ . build_msg CONTAINER "Image built"