From f51d7d686b1f46c987dae32e5585c62df470e728 Mon Sep 17 00:00:00 2001 From: roblinlovelace Date: Mon, 2 Nov 2026 22:24:27 +0000 Subject: [PATCH 1/3] perf: slim images (-2.06 GB on pythonr, -258 MB on python), faster builds, and multi-threaded OpenBLAS/GDAL/Arrow defaults --- .github/workflows/build-docker.yml | 2 ++ minimal-slim/Dockerfile | 13 ++++--- minimal/Dockerfile | 15 ++++---- osgeo/Dockerfile | 12 +++---- python/Dockerfile | 17 ++++----- pythonr/Dockerfile | 55 +++++++++++++++++++++--------- rocker-rpy/Dockerfile | 40 +++++++++++----------- rust/Dockerfile | 27 ++++++--------- suggests/Dockerfile | 4 ++- 9 files changed, 105 insertions(+), 80 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 4a0fbb3..0660f8e 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -52,5 +52,7 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=${{ inputs.image }} + cache-to: type=gha,mode=max,scope=${{ inputs.image }} secrets: | "GITHUB_PAT=${{ secrets.GITHUB_TOKEN }}" diff --git a/minimal-slim/Dockerfile b/minimal-slim/Dockerfile index 8c73223..f8593a5 100644 --- a/minimal-slim/Dockerfile +++ b/minimal-slim/Dockerfile @@ -2,10 +2,16 @@ ARG R_VER=4.6.2 FROM rocker/r-ver:${R_VER} -# System dependencies: keep only what sf/terra/spData need at runtime/build time +ENV GDAL_NUM_THREADS="ALL_CPUS" \ + GDAL_CACHEMAX="512" \ + VSI_CACHE="TRUE" \ + GDAL_HTTP_MULTIPLEX="YES" + +# System dependencies: keep only what sf/terra/spData need at runtime/build time + multi-threaded OpenBLAS # Omitting: gdal-bin, netcdf-bin, postgis, Jupyter, pandoc, TeX, Java RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + libopenblas0-pthread \ libgdal-dev \ libgeos-dev \ libproj-dev \ @@ -15,13 +21,12 @@ RUN apt-get update \ # R packages: geocompx/geocompkg Imports + VS Code R extension (vscode-R v3+) dependencies # Using install2.r from rocker-versioned2 style (lightweight, no extra system deps) +# Strip binary .so files in the same layer to reduce image size ARG NCPUS=-1 RUN install2.r --error --skipmissing --skipinstalled -n "${NCPUS}" \ sf terra spData units dplyr methods languageserver httpgd jgd rstudioapi processx ps later jsonlite svglite \ + && find /usr/local/lib/R/site-library/*/libs -name '*.so' -exec strip --strip-unneeded {} + 2>/dev/null || true \ && rm -rf /tmp/downloaded_packages -# Strip binary .so files from RSPM installs -RUN find /usr/local/lib/R/site-library/*/libs -name '*.so' -exec strip --strip-unneeded {} + 2>/dev/null || true - # Default command CMD ["R"] diff --git a/minimal/Dockerfile b/minimal/Dockerfile index a9c2c03..77fb62b 100644 --- a/minimal/Dockerfile +++ b/minimal/Dockerfile @@ -4,6 +4,11 @@ LABEL org.opencontainers.image.authors="Robin Lovelace , Jakub org.opencontainers.image.source="https://github.com/geocompx/docker" \ devcontainer.metadata='[{"customizations":{"vscode":{"extensions":["REditorSupport.r","Posit.air-vscode","quarto.quarto"],"settings":{"r.rterm.linux":"/usr/local/bin/R","r.rpath.linux":"/usr/local/bin/R","r.lsp.path":"/usr/local/bin/R","r.plot.backend":"auto","r.sessionWatcher":true,"r.bracketedPaste":true,"r.interactive.executionTarget":"terminal"}}}}]' +ENV GDAL_NUM_THREADS="ALL_CPUS" \ + GDAL_CACHEMAX="512" \ + VSI_CACHE="TRUE" \ + GDAL_HTTP_MULTIPLEX="YES" + RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get purge -y postgis netcdf-bin \ && apt-get autoremove -y \ @@ -14,15 +19,15 @@ RUN apt-get update \ # - languageserver: R LSP support # - httpgd, jgd, rstudioapi, svglite: plot backends & rstudioapi emulation in vscode-R v3+ # - processx, ps, later, jsonlite: required by vscode-R's bundled `sess` package so first-run installation is instantaneous -RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak(c('sf','terra','spData','units','dplyr','languageserver','httpgd','jgd','rstudioapi','processx','ps','later','jsonlite','svglite','methods'), upgrade = FALSE)" +# Strip debug symbols from compiled R package shared objects and clean pkgcache in the same layer +RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak(c('sf','terra','spData','units','dplyr','languageserver','httpgd','jgd','rstudioapi','processx','ps','later','jsonlite','svglite','methods'), upgrade = FALSE)" \ + && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ + && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* # Install arf (modern Rust-based R console used by vscode-R persistent interactive sessions) RUN wget -qO- https://github.com/eitsupi/arf/releases/latest/download/arf-console-installer.sh | env CARGO_DIST_FORCE_INSTALL_DIR=/usr/local sh \ && /usr/local/bin/arf --version -# Strip debug symbols from compiled R package shared objects to save ~200MB -RUN strip /usr/local/lib/R/site-library/*/libs/*.so - # Disable inline RMarkdown/Quarto chunk output in RStudio RUN echo '{' > /etc/rstudio/rstudio-prefs.json \ && echo ' "rmd_chunk_output_inline": false' >> /etc/rstudio/rstudio-prefs.json \ @@ -35,5 +40,3 @@ RUN echo 'if (interactive() && (Sys.getenv("TERM_PROGRAM") == "vscode" || Sys.ge && echo ' options(device = httpgd::hgd)' >> /usr/local/lib/R/etc/Rprofile.site \ && echo ' }' >> /usr/local/lib/R/etc/Rprofile.site \ && echo '}' >> /usr/local/lib/R/etc/Rprofile.site - -RUN rm -rf /var/lib/apt/lists/* diff --git a/osgeo/Dockerfile b/osgeo/Dockerfile index 8f3a7f5..4cddc72 100644 --- a/osgeo/Dockerfile +++ b/osgeo/Dockerfile @@ -1,9 +1,7 @@ FROM rocker/geospatial:dev-osgeo -RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('geocompx/geocompkg', upgrade = TRUE)" - -# Set RStudio preferences -# No inline code: -RUN echo '{' >> /etc/rstudio/rstudio-prefs.json -RUN echo ' "rmd_chunk_output_inline": false' >> /etc/rstudio/rstudio-prefs.json -RUN echo '}' >> /etc/rstudio/rstudio-prefs.json +RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('geocompx/geocompkg', upgrade = TRUE)" \ + && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ + && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* +# Set RStudio preferences (no inline code) +RUN printf '{\n "rmd_chunk_output_inline": false\n}\n' > /etc/rstudio/rstudio-prefs.json diff --git a/python/Dockerfile b/python/Dockerfile index b2bf169..17f1d51 100644 --- a/python/Dockerfile +++ b/python/Dockerfile @@ -6,12 +6,16 @@ ARG QUARTO_VERSION=1.11.9 LABEL devcontainer.metadata='[{"customizations":{"vscode":{"extensions":["quarto.quarto","ms-python.python","ms-toolsai.jupyter"],"settings":{"python.defaultInterpreterPath":"/usr/local/bin/python"}}}}]' ENV QUARTO_PYTHON="/usr/local/bin/python" \ - RETICULATE_PYTHON="/usr/local/bin/python" - -# Install dependencies, git, and gh cli + RETICULATE_PYTHON="/usr/local/bin/python" \ + GDAL_NUM_THREADS="ALL_CPUS" \ + GDAL_CACHEMAX="512" \ + VSI_CACHE="TRUE" \ + GDAL_HTTP_MULTIPLEX="YES" \ + PYOGRIO_USE_ARROW="1" + +# Install dependencies, git, and gh cli (no build-essential needed since uv installs binary wheels) RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ - build-essential \ curl \ git \ unzip \ @@ -20,7 +24,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list \ && apt-get update \ - && apt-get install -y gh \ + && apt-get install -y --no-install-recommends gh \ && rm -rf /var/lib/apt/lists/* # Install quarto @@ -39,6 +43,3 @@ RUN wget -q -O /tmp/requirements.txt https://raw.githubusercontent.com/geocompx/ && sed -i 's/==/>=/g' /tmp/requirements.txt \ && uv pip install --system --no-cache -r /tmp/requirements.txt seaborn openpyxl statsmodels pyarrow \ && rm /tmp/requirements.txt - -# Clean up build tools to reduce image size (optional but recommended) -RUN apt purge -y build-essential && apt autoremove -y && rm -rf /var/lib/apt/lists/* diff --git a/pythonr/Dockerfile b/pythonr/Dockerfile index 08a8671..4dea814 100644 --- a/pythonr/Dockerfile +++ b/pythonr/Dockerfile @@ -4,21 +4,21 @@ LABEL org.opencontainers.image.authors="Robin Lovelace " \ org.opencontainers.image.source="https://github.com/geocompx/docker" \ devcontainer.metadata='[{"customizations":{"vscode":{"extensions":["REditorSupport.r","Posit.air-vscode","quarto.quarto","ms-python.python"],"settings":{"r.rterm.linux":"/usr/local/bin/R","r.rpath.linux":"/usr/local/bin/R","r.lsp.path":"/usr/local/bin/R","r.plot.backend":"auto","r.sessionWatcher":true,"r.bracketedPaste":true,"r.interactive.executionTarget":"terminal"}}}}]' -RUN apt-get update && apt-get install -y --no-install-recommends \ - curl \ - libdeflate0 \ - locales \ - xz-utils \ - && rm -rf /var/lib/apt/lists/* - # Install R from Posit's precompiled Debian repository (auto-detecting Debian 12 bookworm vs Debian 13 trixie) +# along with multi-threaded OpenBLAS and required C/C++ runtime/header libraries using --no-install-recommends ARG R_VERSION=4.6.2 RUN . /etc/os-release && \ if [ "${VERSION_ID}" = "12" ]; then R_VER="4.6.0"; else R_VER="${R_VERSION}"; fi && \ - curl -fSL -o /tmp/r.deb "https://cdn.posit.co/r/debian-${VERSION_ID}/pkgs/r-${R_VER}_1_$(dpkg --print-architecture).deb" && \ apt-get update && \ - apt-get install -y /tmp/r.deb \ - libblas-dev \ + apt-get install -y --no-install-recommends \ + curl \ + libdeflate0 \ + locales \ + xz-utils && \ + curl -fSL -o /tmp/r.deb "https://cdn.posit.co/r/debian-${VERSION_ID}/pkgs/r-${R_VER}_1_$(dpkg --print-architecture).deb" && \ + apt-get install -y --no-install-recommends /tmp/r.deb \ + libopenblas0-pthread \ + libopenblas-dev \ liblapack-dev \ libomp-dev \ gfortran \ @@ -27,14 +27,35 @@ RUN . /etc/os-release && \ libgeos-dev \ libproj-dev \ libglpk40 \ + libglpk-dev \ + libcurl4-openssl-dev \ + libssl-dev \ + libxml2-dev \ + libfontconfig1-dev \ + libfreetype6-dev \ + libfribidi-dev \ + libharfbuzz-dev \ + libgit2-dev \ + libmagick++-dev \ + libnode-dev \ + libcairo2-dev \ + libx11-dev \ + libuv1-dev \ + libabsl-dev \ && ln -sfn "/opt/R/${R_VER}" /opt/R/current \ && ln -sfn /opt/R/current/bin/R /usr/local/bin/R \ && ln -sfn /opt/R/current/bin/Rscript /usr/local/bin/Rscript \ + && ln -sfn /opt/quarto/bin/tools/pandoc /usr/local/bin/pandoc \ && rm -rf /tmp/r.deb /var/lib/apt/lists/* ENV PATH="/opt/R/current/bin:/usr/local/bin:${PATH}" \ QUARTO_PYTHON="/usr/local/bin/python" \ - RETICULATE_PYTHON="/usr/local/bin/python" + RETICULATE_PYTHON="/usr/local/bin/python" \ + GDAL_NUM_THREADS="ALL_CPUS" \ + GDAL_CACHEMAX="512" \ + VSI_CACHE="TRUE" \ + GDAL_HTTP_MULTIPLEX="YES" \ + PYOGRIO_USE_ARROW="1" # Configure Rprofile.site and /root/.Rprofile with P3M binary repository and HTTPUserAgent # so both pak and base install.packages() receive precompiled Linux binary packages from P3M @@ -55,12 +76,12 @@ RUN cp /opt/R/current/lib/R/etc/Rprofile.site /etc/R/Rprofile.site && \ RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/eitsupi/arf/releases/latest/download/arf-console-installer.sh | env CARGO_DIST_FORCE_INSTALL_DIR=/usr/local sh \ && /usr/local/bin/arf --version -# Install pak from precompiled binary -RUN R -e "install.packages('pak')" - -# Install geocompkg (including Suggests) + VS Code R extension (vscode-R v3+) dependencies -# using pak so system requirements and precompiled P3M/r-universe binaries are resolved in parallel -RUN Rscript -e "options(repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak(c('sf', 'geocompkg', 'languageserver', 'httpgd', 'jgd', 'rstudioapi', 'processx', 'ps', 'later', 'jsonlite', 'svglite', 'reticulate'), dependencies = TRUE)" && \ +# Install pak + geocompkg (including Suggests) + VS Code R extension (vscode-R v3+) dependencies +# with pkg.sysreqs = FALSE (all required C/C++ runtime libs are installed above with --no-install-recommends) +# and strip debug symbols from compiled R shared objects in the same layer +RUN R -e "install.packages('pak')" && \ + Rscript -e "options(pkg.sysreqs = FALSE, repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak(c('sf', 'geocompkg', 'languageserver', 'httpgd', 'jgd', 'rstudioapi', 'processx', 'ps', 'later', 'jsonlite', 'svglite', 'reticulate'), dependencies = TRUE)" && \ + strip --strip-debug /opt/R/current/lib/R/library/*/libs/*.so 2>/dev/null || true && \ ln -sf /usr/local/bin/python /usr/bin/python3 && \ ln -sf /usr/local/bin/python /usr/bin/python && \ rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* diff --git a/rocker-rpy/Dockerfile b/rocker-rpy/Dockerfile index 60765c3..f594ea4 100644 --- a/rocker-rpy/Dockerfile +++ b/rocker-rpy/Dockerfile @@ -9,31 +9,29 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3 \ python3-dev \ python3-pip \ - swig && \ - rm -rf /var/lib/apt/lists/* - -# Create a symbolic link so the 'python' command defaults to 'python3' -# The '-f' flag forces the creation of the symbolic link, overwriting any existing file. -RUN ln -sf /usr/bin/python3 /usr/bin/python - -# Create a symbolic link so the 'pip' command defaults to 'pip3' -# The '-f' flag forces the creation of the symbolic link, overwriting any existing file. -RUN ln -sf /usr/bin/pip3 /usr/bin/pip + swig \ + && ln -sf /usr/bin/python3 /usr/bin/python \ + && ln -sf /usr/bin/pip3 /usr/bin/pip \ + && rm -rf /var/lib/apt/lists/* # Install reticulate R package to enable R-Python interoperability -# This step remains the same as it is a separate R installation. -RUN R -e "install.packages('reticulate', repos='https://cloud.r-project.org/')" +RUN R -e "install.packages('reticulate', repos='https://cloud.r-project.org/')" \ + && rm -rf /tmp/* + +# Set the environment variables for Quarto, Reticulate, GDAL, and Pyogrio +ENV QUARTO_PYTHON=/usr/bin/python \ + RETICULATE_PYTHON=/usr/bin/python \ + GDAL_NUM_THREADS="ALL_CPUS" \ + GDAL_CACHEMAX="512" \ + VSI_CACHE="TRUE" \ + GDAL_HTTP_MULTIPLEX="YES" \ + PYOGRIO_USE_ARROW="1" -# Set the environment variable for Quarto to use the system Python 3. -# The `which python3` command finds the path of the globally installed executable. -ENV QUARTO_PYTHON=/usr/bin/python +# Install uv for fast parallel Python wheel resolution +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ -# Install project requirements globally using the system's pip3. -# We use `pip3` to ensure we are using the package manager for Python 3. -# The `--break-system-packages` flag is added to override the security feature. -# The `--ignore-installed` flag is added to prevent pip from trying to uninstall -# packages that are managed by the system. +# Install project requirements globally using uv RUN wget -q -O /tmp/requirements.txt https://github.com/geocompx/geocompy/raw/refs/heads/main/requirements.txt \ && sed -i 's/==/>=/g' /tmp/requirements.txt \ - && pip3 install --no-cache-dir --break-system-packages --ignore-installed -r /tmp/requirements.txt \ + && uv pip install --system --break-system-packages --reinstall-package pyyaml --no-cache -r /tmp/requirements.txt \ && rm /tmp/requirements.txt diff --git a/rust/Dockerfile b/rust/Dockerfile index 0e25c41..42a32db 100644 --- a/rust/Dockerfile +++ b/rust/Dockerfile @@ -3,29 +3,24 @@ FROM ghcr.io/geocompx/suggests # od2net R package: https://urban-analytics-technology-platform.github.io/od2net/r/ RUN git clone --depth 1 https://github.com/a-b-street/od2net.git /tmp/od2net \ && R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::local_install('/tmp/od2net/r', upgrade = TRUE, dependencies = TRUE)" \ - && rm -rf /tmp/od2net + && rm -rf /tmp/od2net /root/.cache/R/pkgcache + # robinlovelace/simodels: -RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('robinlovelace/simodels', upgrade = TRUE, dependencies = TRUE)" +RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('robinlovelace/simodels', upgrade = TRUE, dependencies = TRUE)" \ + && rm -rf /tmp/* /root/.cache/R/pkgcache RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ - && rm -rf /var/lib/apt/lists/* \ - && curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y \ + osmium-tool \ + && curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable --profile minimal -y \ && export PATH="$HOME/.cargo/bin:$PATH" \ && echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.profile \ - # Also make cargo available and rustc available with ln -s: && ln -s /root/.cargo/bin/cargo /usr/local/bin/cargo \ && ln -s /root/.cargo/bin/rustc /usr/local/bin/rustc \ && cargo install --locked --git https://github.com/Urban-Analytics-Technology-Platform/od2net \ - && cd /tmp \ - && git clone https://github.com/felt/tippecanoe.git \ - && cd tippecanoe \ - && make -j \ - && make install \ + && ln -s /root/.cargo/bin/od2net /usr/local/bin/od2net \ + && git clone --depth 1 https://github.com/felt/tippecanoe.git /tmp/tippecanoe \ + && make -C /tmp/tippecanoe -j"$(nproc)" \ + && make -C /tmp/tippecanoe install \ && tippecanoe --version \ - && echo "deb http://archive.ubuntu.com/ubuntu/ jammy main restricted" >> /etc/apt/sources.list \ - && apt-get update \ - && apt-get install -y osmium-tool - -# Ensure od2net is available in the PATH: -RUN ln -s /root/.cargo/bin/od2net /usr/local/bin/od2net + && rm -rf /tmp/tippecanoe /root/.cargo/registry /root/.cargo/git /var/lib/apt/lists/* diff --git a/suggests/Dockerfile b/suggests/Dockerfile index a1fe83c..ab1bf15 100644 --- a/suggests/Dockerfile +++ b/suggests/Dockerfile @@ -3,4 +3,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglpk40 \ nodejs \ && rm -rf /var/lib/apt/lists/* -RUN R -e "options(repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak('geocompkg', dependencies = TRUE, upgrade = TRUE)" +RUN R -e "options(repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak('geocompkg', dependencies = TRUE, upgrade = TRUE)" \ + && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ + && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* From c3ad64748076eb500a185c508bf48c548e8b13fd Mon Sep 17 00:00:00 2001 From: roblinlovelace Date: Mon, 2 Nov 2026 22:56:52 +0000 Subject: [PATCH 2/3] perf(contender-1): dev-ready slim (-3.05 GB/-49% on pythonr, -526 MB/-26% on python) retaining C/C++ -dev headers --- minimal-slim/Dockerfile | 12 +++++------ minimal/Dockerfile | 9 +++----- osgeo/Dockerfile | 7 ++++--- python/Dockerfile | 46 +++++++++++++++++++++++++---------------- pythonr/Dockerfile | 24 ++++++++++++--------- rocker-rpy/Dockerfile | 7 +++---- suggests/Dockerfile | 9 +++++--- 7 files changed, 64 insertions(+), 50 deletions(-) diff --git a/minimal-slim/Dockerfile b/minimal-slim/Dockerfile index f8593a5..e5dcb5e 100644 --- a/minimal-slim/Dockerfile +++ b/minimal-slim/Dockerfile @@ -8,7 +8,7 @@ ENV GDAL_NUM_THREADS="ALL_CPUS" \ GDAL_HTTP_MULTIPLEX="YES" # System dependencies: keep only what sf/terra/spData need at runtime/build time + multi-threaded OpenBLAS -# Omitting: gdal-bin, netcdf-bin, postgis, Jupyter, pandoc, TeX, Java +# Remove unused third-party static .a archives in the same layer RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ libopenblas0-pthread \ @@ -17,16 +17,16 @@ RUN apt-get update \ libproj-dev \ libudunits2-dev \ libssl-dev \ - && rm -rf /var/lib/apt/lists/* + && find /usr/lib/*-linux-gnu -name "*.a" ! -name "*nonshared*" ! -name "libc.a" ! -name "libm.a" -delete \ + && rm -rf /usr/share/doc/* /usr/share/man/* /var/lib/apt/lists/* # R packages: geocompx/geocompkg Imports + VS Code R extension (vscode-R v3+) dependencies -# Using install2.r from rocker-versioned2 style (lightweight, no extra system deps) -# Strip binary .so files in the same layer to reduce image size +# Strip binary .so files and static vignettes in the same layer to reduce image size ARG NCPUS=-1 RUN install2.r --error --skipmissing --skipinstalled -n "${NCPUS}" \ sf terra spData units dplyr methods languageserver httpgd jgd rstudioapi processx ps later jsonlite svglite \ - && find /usr/local/lib/R/site-library/*/libs -name '*.so' -exec strip --strip-unneeded {} + 2>/dev/null || true \ - && rm -rf /tmp/downloaded_packages + && (find /usr/local/lib/R/site-library/*/libs -name '*.so' -exec strip --strip-unneeded {} + 2>/dev/null || true) \ + && rm -rf /usr/local/lib/R/site-library/*/doc /tmp/downloaded_packages # Default command CMD ["R"] diff --git a/minimal/Dockerfile b/minimal/Dockerfile index 77fb62b..92d317e 100644 --- a/minimal/Dockerfile +++ b/minimal/Dockerfile @@ -15,14 +15,11 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Install essential geocompkg Imports + VS Code R extension (vscode-R v3+) session/plot/LSP dependencies: -# - languageserver: R LSP support -# - httpgd, jgd, rstudioapi, svglite: plot backends & rstudioapi emulation in vscode-R v3+ -# - processx, ps, later, jsonlite: required by vscode-R's bundled `sess` package so first-run installation is instantaneous +# Install essential geocompkg Imports + VS Code R extension (vscode-R v3+) session/plot/LSP dependencies # Strip debug symbols from compiled R package shared objects and clean pkgcache in the same layer RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak(c('sf','terra','spData','units','dplyr','languageserver','httpgd','jgd','rstudioapi','processx','ps','later','jsonlite','svglite','methods'), upgrade = FALSE)" \ - && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ - && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* + && (strip --strip-unneeded /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true) \ + && rm -rf /usr/local/lib/R/site-library/*/doc /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* # Install arf (modern Rust-based R console used by vscode-R persistent interactive sessions) RUN wget -qO- https://github.com/eitsupi/arf/releases/latest/download/arf-console-installer.sh | env CARGO_DIST_FORCE_INSTALL_DIR=/usr/local sh \ diff --git a/osgeo/Dockerfile b/osgeo/Dockerfile index 4cddc72..7d240ff 100644 --- a/osgeo/Dockerfile +++ b/osgeo/Dockerfile @@ -1,7 +1,8 @@ FROM rocker/geospatial:dev-osgeo -RUN R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('geocompx/geocompkg', upgrade = TRUE)" \ - && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ - && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* +RUN export MAKEFLAGS="-j$(nproc)" \ + && R -e "if (!requireNamespace('pak', quietly = TRUE)) install.packages('pak', repos = 'https://cloud.r-project.org/'); pak::pak('geocompx/geocompkg', upgrade = TRUE)" \ + && (strip --strip-unneeded /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true) \ + && rm -rf /usr/local/lib/R/site-library/*/doc /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* # Set RStudio preferences (no inline code) RUN printf '{\n "rmd_chunk_output_inline": false\n}\n' > /etc/rstudio/rstudio-prefs.json diff --git a/python/Dockerfile b/python/Dockerfile index 17f1d51..7b52d26 100644 --- a/python/Dockerfile +++ b/python/Dockerfile @@ -13,33 +13,43 @@ ENV QUARTO_PYTHON="/usr/local/bin/python" \ GDAL_HTTP_MULTIPLEX="YES" \ PYOGRIO_USE_ARROW="1" -# Install dependencies, git, and gh cli (no build-essential needed since uv installs binary wheels) -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - git \ - unzip \ - wget \ +# Configure dpkg to exclude documentation, manpages, and locale translations across all layers, +# and install dependencies, git, gh cli, and quarto in a single clean layer with SHA-256 inode deduplication +RUN printf "path-exclude /usr/share/doc/*\npath-exclude /usr/share/man/*\npath-exclude /usr/share/locale/*\npath-exclude /usr/share/info/*\n" > /etc/dpkg/dpkg.cfg.d/docker-no-doc \ + && apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + git \ + unzip \ + wget \ && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list \ - && apt-get update \ - && apt-get install -y --no-install-recommends gh \ - && rm -rf /var/lib/apt/lists/* - -# Install quarto -RUN arch="$(dpkg --print-architecture)" \ + && arch="$(dpkg --print-architecture)" \ && wget -q "https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-${arch}.deb" \ && apt-get update \ - && apt-get install -y --no-install-recommends "./quarto-${QUARTO_VERSION}-linux-${arch}.deb" \ + && apt-get install -y --no-install-recommends gh "./quarto-${QUARTO_VERSION}-linux-${arch}.deb" \ && rm "quarto-${QUARTO_VERSION}-linux-${arch}.deb" \ - && rm -rf /var/lib/apt/lists/* + && python -c 'import os,hashlib; seen={}; [([os.unlink(p),os.link(seen[h],p)] if h in seen else seen.setdefault(h,p)) for r,_,fs in os.walk("/opt/quarto") for f in fs if not os.path.islink(p:=os.path.join(r,f)) and (s:=os.path.getsize(p))>4096 and (h:=(s,hashlib.sha256(open(p,"rb").read()).hexdigest()))]' \ + && rm -rf /usr/share/doc/* /usr/share/man/* /usr/share/locale/* /var/lib/apt/lists/* # Install uv for fast Python package & project management COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ -# Install requirements using uv for fast parallel wheel resolution -RUN wget -q -O /tmp/requirements.txt https://raw.githubusercontent.com/geocompx/geocompy/main/requirements.txt \ +# Install requirements using uv, strip debug symbols from compiled C/C++ shared libraries, +# prune bundled package unit test suites/C++ headers, and hardlink duplicate files in site-packages +RUN apt-get update && apt-get install -y --no-install-recommends binutils \ + && wget -q -O /tmp/requirements.txt https://raw.githubusercontent.com/geocompx/geocompy/main/requirements.txt \ && sed -i 's/==/>=/g' /tmp/requirements.txt \ && uv pip install --system --no-cache -r /tmp/requirements.txt seaborn openpyxl statsmodels pyarrow \ - && rm /tmp/requirements.txt + && (find /usr/local/lib/python3.14/site-packages -name "*.so*" -type f -exec strip --strip-unneeded {} + 2>/dev/null || true) \ + && (find /usr/local/lib/python3.14/site-packages -type d -name "tests" -prune -exec rm -rf {} + 2>/dev/null || true) \ + && rm -rf /usr/local/lib/python3.14/site-packages/pyarrow/include \ + /usr/local/lib/python3.14/site-packages/numpy/_core/include \ + /usr/local/lib/python3.14/site-packages/numpy/f2py/src \ + /usr/local/lib/python3.14/site-packages/jupyterlab/galata \ + /usr/local/lib/python3.14/site-packages/jedi/third_party/django-stubs \ + && (find /usr/local/lib/python3.14/site-packages -name "*.js.map" -delete 2>/dev/null || true) \ + && python -c 'import os,hashlib; seen={}; [([os.unlink(p),os.link(seen[h],p)] if h in seen else seen.setdefault(h,p)) for r,_,fs in os.walk("/usr/local/lib/python3.14/site-packages") for f in fs if not os.path.islink(p:=os.path.join(r,f)) and (s:=os.path.getsize(p))>4096 and (h:=(s,hashlib.sha256(open(p,"rb").read()).hexdigest()))]' \ + && apt-get purge -y --auto-remove binutils \ + && rm -rf /tmp/requirements.txt /var/lib/apt/lists/* diff --git a/pythonr/Dockerfile b/pythonr/Dockerfile index 4dea814..296c1a8 100644 --- a/pythonr/Dockerfile +++ b/pythonr/Dockerfile @@ -4,8 +4,8 @@ LABEL org.opencontainers.image.authors="Robin Lovelace " \ org.opencontainers.image.source="https://github.com/geocompx/docker" \ devcontainer.metadata='[{"customizations":{"vscode":{"extensions":["REditorSupport.r","Posit.air-vscode","quarto.quarto","ms-python.python"],"settings":{"r.rterm.linux":"/usr/local/bin/R","r.rpath.linux":"/usr/local/bin/R","r.lsp.path":"/usr/local/bin/R","r.plot.backend":"auto","r.sessionWatcher":true,"r.bracketedPaste":true,"r.interactive.executionTarget":"terminal"}}}}]' -# Install R from Posit's precompiled Debian repository (auto-detecting Debian 12 bookworm vs Debian 13 trixie) -# along with multi-threaded OpenBLAS and required C/C++ runtime/header libraries using --no-install-recommends +# Contender 1 (Dev-Ready Slim): Keep C/C++ -dev headers for source builds, drop Clang libomp-dev (GCC uses libgomp1), +# and remove unused third-party static .a archives in /usr/lib/*-linux-gnu while preserving /usr/lib/gcc and *nonshared.a ARG R_VERSION=4.6.2 RUN . /etc/os-release && \ if [ "${VERSION_ID}" = "12" ]; then R_VER="4.6.0"; else R_VER="${R_VERSION}"; fi && \ @@ -20,7 +20,6 @@ RUN . /etc/os-release && \ libopenblas0-pthread \ libopenblas-dev \ liblapack-dev \ - libomp-dev \ gfortran \ libudunits2-dev \ libgdal-dev \ @@ -42,11 +41,12 @@ RUN . /etc/os-release && \ libx11-dev \ libuv1-dev \ libabsl-dev \ + && find /usr/lib/*-linux-gnu -name "*.a" ! -name "*nonshared*" ! -name "libc.a" ! -name "libm.a" -delete \ && ln -sfn "/opt/R/${R_VER}" /opt/R/current \ && ln -sfn /opt/R/current/bin/R /usr/local/bin/R \ && ln -sfn /opt/R/current/bin/Rscript /usr/local/bin/Rscript \ && ln -sfn /opt/quarto/bin/tools/pandoc /usr/local/bin/pandoc \ - && rm -rf /tmp/r.deb /var/lib/apt/lists/* + && rm -rf /tmp/r.deb /usr/share/doc/* /usr/share/man/* /var/lib/apt/lists/* ENV PATH="/opt/R/current/bin:/usr/local/bin:${PATH}" \ QUARTO_PYTHON="/usr/local/bin/python" \ @@ -58,7 +58,6 @@ ENV PATH="/opt/R/current/bin:/usr/local/bin:${PATH}" \ PYOGRIO_USE_ARROW="1" # Configure Rprofile.site and /root/.Rprofile with P3M binary repository and HTTPUserAgent -# so both pak and base install.packages() receive precompiled Linux binary packages from P3M RUN . /etc/os-release && \ mkdir -p /etc/R /opt/R/current/lib/R/etc /root && \ cat < /opt/R/current/lib/R/etc/Rprofile.site @@ -76,12 +75,17 @@ RUN cp /opt/R/current/lib/R/etc/Rprofile.site /etc/R/Rprofile.site && \ RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/eitsupi/arf/releases/latest/download/arf-console-installer.sh | env CARGO_DIST_FORCE_INSTALL_DIR=/usr/local sh \ && /usr/local/bin/arf --version -# Install pak + geocompkg (including Suggests) + VS Code R extension (vscode-R v3+) dependencies -# with pkg.sysreqs = FALSE (all required C/C++ runtime libs are installed above with --no-install-recommends) -# and strip debug symbols from compiled R shared objects in the same layer -RUN R -e "install.packages('pak')" && \ +# Parallel source build via MAKEFLAGS, strip .so debug symbols, prune static vignettes & googlePolylines Boost header cache, +# hardlink duplicate files, and assert zero missing shared libraries across all installed R .so objects +RUN export MAKEFLAGS="-j$(nproc)" && \ + R -e "install.packages('pak')" && \ Rscript -e "options(pkg.sysreqs = FALSE, repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak(c('sf', 'geocompkg', 'languageserver', 'httpgd', 'jgd', 'rstudioapi', 'processx', 'ps', 'later', 'jsonlite', 'svglite', 'reticulate'), dependencies = TRUE)" && \ - strip --strip-debug /opt/R/current/lib/R/library/*/libs/*.so 2>/dev/null || true && \ + ! (LD_LIBRARY_PATH="/opt/R/current/lib/R/lib:${LD_LIBRARY_PATH}" ldd /opt/R/current/lib/R/library/*/libs/*.so 2>/dev/null | grep "not found") && \ + (strip --strip-unneeded /opt/R/current/lib/R/library/*/libs/*.so 2>/dev/null || true) && \ + rm -rf /opt/R/current/lib/R/library/*/doc \ + /opt/R/current/lib/R/library/googlePolylines/i \ + /opt/R/current/lib/R/doc && \ + python -c 'import os,hashlib; seen={}; [([os.unlink(p),os.link(seen[h],p)] if h in seen else seen.setdefault(h,p)) for r,_,fs in os.walk("/opt/R/current/lib/R/library") for f in fs if not os.path.islink(p:=os.path.join(r,f)) and (s:=os.path.getsize(p))>4096 and (h:=(s,hashlib.sha256(open(p,"rb").read()).hexdigest()))]' && \ ln -sf /usr/local/bin/python /usr/bin/python3 && \ ln -sf /usr/local/bin/python /usr/bin/python && \ rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* diff --git a/rocker-rpy/Dockerfile b/rocker-rpy/Dockerfile index f594ea4..72291bd 100644 --- a/rocker-rpy/Dockerfile +++ b/rocker-rpy/Dockerfile @@ -2,9 +2,6 @@ FROM ghcr.io/geocompx/minimal # Install core Python 3 packages and other dependencies. -# - python3-dev: Headers needed to compile certain Python packages with C extensions. -# - python3-pip: The package installer for Python 3, installed globally. -# - swig: Used for wrapping C/C++ libraries for Python. RUN apt-get update && apt-get install -y --no-install-recommends \ python3 \ python3-dev \ @@ -30,8 +27,10 @@ ENV QUARTO_PYTHON=/usr/bin/python \ # Install uv for fast parallel Python wheel resolution COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ -# Install project requirements globally using uv +# Install project requirements globally using uv, strip debug symbols, and prune test directories RUN wget -q -O /tmp/requirements.txt https://github.com/geocompx/geocompy/raw/refs/heads/main/requirements.txt \ && sed -i 's/==/>=/g' /tmp/requirements.txt \ && uv pip install --system --break-system-packages --reinstall-package pyyaml --no-cache -r /tmp/requirements.txt \ + && (find /usr/local/lib/python*/dist-packages -name "*.so*" -type f -exec strip --strip-unneeded {} + 2>/dev/null || true) \ + && (find /usr/local/lib/python*/dist-packages -type d -name "tests" -prune -exec rm -rf {} + 2>/dev/null || true) \ && rm /tmp/requirements.txt diff --git a/suggests/Dockerfile b/suggests/Dockerfile index ab1bf15..526f3b2 100644 --- a/suggests/Dockerfile +++ b/suggests/Dockerfile @@ -3,6 +3,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libglpk40 \ nodejs \ && rm -rf /var/lib/apt/lists/* -RUN R -e "options(repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak('geocompkg', dependencies = TRUE, upgrade = TRUE)" \ - && strip --strip-debug /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true \ - && rm -rf /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* +RUN export MAKEFLAGS="-j$(nproc)" \ + && R -e "options(repos = c(geocompx = 'https://geocompx.r-universe.dev', mlrorg = 'https://mlr-org.r-universe.dev', getOption('repos'))); pak::pak('geocompkg', dependencies = TRUE, upgrade = TRUE)" \ + && (strip --strip-unneeded /usr/local/lib/R/site-library/*/libs/*.so 2>/dev/null || true) \ + && rm -rf /usr/local/lib/R/site-library/*/doc \ + /usr/local/lib/R/site-library/googlePolylines/i \ + /tmp/* /root/.cache/R/pkgcache /var/lib/apt/lists/* From 9cda58366144ad9de431396fe92e2ae595935b51 Mon Sep 17 00:00:00 2001 From: roblinlovelace Date: Mon, 2 Nov 2026 22:57:51 +0000 Subject: [PATCH 3/3] perf(contender-2): ultra-slim runtime pythonr (-3.35 GB / -53.9%, down to 2.87 GB) with build-time ldd check --- pythonr/Dockerfile | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/pythonr/Dockerfile b/pythonr/Dockerfile index 296c1a8..710d90d 100644 --- a/pythonr/Dockerfile +++ b/pythonr/Dockerfile @@ -4,8 +4,8 @@ LABEL org.opencontainers.image.authors="Robin Lovelace " \ org.opencontainers.image.source="https://github.com/geocompx/docker" \ devcontainer.metadata='[{"customizations":{"vscode":{"extensions":["REditorSupport.r","Posit.air-vscode","quarto.quarto","ms-python.python"],"settings":{"r.rterm.linux":"/usr/local/bin/R","r.rpath.linux":"/usr/local/bin/R","r.lsp.path":"/usr/local/bin/R","r.plot.backend":"auto","r.sessionWatcher":true,"r.bracketedPaste":true,"r.interactive.executionTarget":"terminal"}}}}]' -# Contender 1 (Dev-Ready Slim): Keep C/C++ -dev headers for source builds, drop Clang libomp-dev (GCC uses libgomp1), -# and remove unused third-party static .a archives in /usr/lib/*-linux-gnu while preserving /usr/lib/gcc and *nonshared.a +# Contender 2 (Ultra-Slim Runtime): Posit R (which includes gcc/g++/gfortran/make/openblas-dev) + exact runtime .so libraries +# without 650 MB of libboost1.83-dev / libllvm19 / libspatialite-dev / python3.13 / third-party static .a archives ARG R_VERSION=4.6.2 RUN . /etc/os-release && \ if [ "${VERSION_ID}" = "12" ]; then R_VER="4.6.0"; else R_VER="${R_VERSION}"; fi && \ @@ -18,29 +18,20 @@ RUN . /etc/os-release && \ curl -fSL -o /tmp/r.deb "https://cdn.posit.co/r/debian-${VERSION_ID}/pkgs/r-${R_VER}_1_$(dpkg --print-architecture).deb" && \ apt-get install -y --no-install-recommends /tmp/r.deb \ libopenblas0-pthread \ - libopenblas-dev \ - liblapack-dev \ - gfortran \ - libudunits2-dev \ - libgdal-dev \ - libgeos-dev \ - libproj-dev \ + liblapack3 \ + libgdal36 \ + libgeos-c1t64 \ + libproj25 \ + libudunits2-0 \ libglpk40 \ - libglpk-dev \ - libcurl4-openssl-dev \ - libssl-dev \ - libxml2-dev \ - libfontconfig1-dev \ - libfreetype6-dev \ - libfribidi-dev \ - libharfbuzz-dev \ - libgit2-dev \ - libmagick++-dev \ - libnode-dev \ - libcairo2-dev \ - libx11-dev \ - libuv1-dev \ - libabsl-dev \ + libmagick++-7.q16-5 \ + libnode115 \ + libgit2-1.9 \ + libabsl20240722 \ + libuv1t64 \ + libfribidi0 \ + libharfbuzz0b \ + libtiffxx6 \ && find /usr/lib/*-linux-gnu -name "*.a" ! -name "*nonshared*" ! -name "libc.a" ! -name "libm.a" -delete \ && ln -sfn "/opt/R/${R_VER}" /opt/R/current \ && ln -sfn /opt/R/current/bin/R /usr/local/bin/R \