From 9417c284d3baf0f10534b9e3cc0a0c3ffe9c8544 Mon Sep 17 00:00:00 2001 From: ngosang Date: Wed, 26 Oct 2022 21:00:19 +0200 Subject: [PATCH 1/2] Reduce Docker image size * Remove compiled sources. Most of them are never used. Those in use are compiled in the first run really fast. * Copy only source code and Docker entypoint * Image size reduced by 41 MB (195 MB -> 154 MB uncompressed) --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 64aa8bcef..71e27f0f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,21 +45,21 @@ RUN apk upgrade --no-cache \ uwsgi \ uwsgi-python3 \ brotli \ - && pip3 install --upgrade pip wheel setuptools \ && pip3 install --no-cache -r requirements.txt \ && apk del build-dependencies \ - && rm -rf /root/.cache + && rm -rf /root/.cache \ + && find /usr/lib/python*/ -name '*.pyc' -delete -COPY --chown=searxng:searxng . . +COPY --chown=searxng:searxng dockerfiles ./dockerfiles +COPY --chown=searxng:searxng searx ./searx ARG TIMESTAMP_SETTINGS=0 ARG TIMESTAMP_UWSGI=0 ARG VERSION_GITCOMMIT=unknown -RUN su searxng -c "/usr/bin/python3 -m compileall -q searx"; \ - touch -c --date=@${TIMESTAMP_SETTINGS} searx/settings.yml; \ - touch -c --date=@${TIMESTAMP_UWSGI} dockerfiles/uwsgi.ini; \ - find /usr/local/searxng/searx/static -a \( -name '*.html' -o -name '*.css' -o -name '*.js' \ +RUN touch -c --date=@${TIMESTAMP_SETTINGS} searx/settings.yml \ + && touch -c --date=@${TIMESTAMP_UWSGI} dockerfiles/uwsgi.ini \ + && find /usr/local/searxng/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 {} \+ From 6b88e857f9df5df6b0f35af618b651271363c2a2 Mon Sep 17 00:00:00 2001 From: ngosang Date: Tue, 29 Nov 2022 23:13:15 +0100 Subject: [PATCH 2/2] fix --- Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 71e27f0f6..79602553d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,8 +22,7 @@ WORKDIR /usr/local/searxng COPY requirements.txt ./requirements.txt -RUN apk upgrade --no-cache \ - && apk add --no-cache -t build-dependencies \ +RUN apk add --no-cache -t build-dependencies \ build-base \ py3-setuptools \ python3-dev \ @@ -47,8 +46,7 @@ RUN apk upgrade --no-cache \ brotli \ && pip3 install --no-cache -r requirements.txt \ && apk del build-dependencies \ - && rm -rf /root/.cache \ - && find /usr/lib/python*/ -name '*.pyc' -delete + && rm -rf /root/.cache COPY --chown=searxng:searxng dockerfiles ./dockerfiles COPY --chown=searxng:searxng searx ./searx @@ -57,7 +55,8 @@ ARG TIMESTAMP_SETTINGS=0 ARG TIMESTAMP_UWSGI=0 ARG VERSION_GITCOMMIT=unknown -RUN touch -c --date=@${TIMESTAMP_SETTINGS} searx/settings.yml \ +RUN su searxng -c "/usr/bin/python3 -m compileall -q searx" \ + && touch -c --date=@${TIMESTAMP_SETTINGS} searx/settings.yml \ && touch -c --date=@${TIMESTAMP_UWSGI} dockerfiles/uwsgi.ini \ && find /usr/local/searxng/searx/static -a \( -name '*.html' -o -name '*.css' -o -name '*.js' \ -o -name '*.svg' -o -name '*.ttf' -o -name '*.eot' \) \