From 4d539f2f7a0ef5452e08a28bf9d130ed626ac792 Mon Sep 17 00:00:00 2001 From: Andrii Rieznik Date: Fri, 28 Jun 2024 18:41:46 +0200 Subject: [PATCH] feat: debian bookworm --- Dockerfile | 116 +++++++++++++++++++++++------------------------------ Makefile | 8 ++-- README.md | 10 ++--- 3 files changed, 59 insertions(+), 75 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a4b2a9..1a48109 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,89 +1,75 @@ -## -# andrejreznik/python-gdal -# -# Build args can be redefined in Makefile or passed as build args to Docker build command +FROM debian:bookworm -ARG BASE_IMAGE=python:3.10.0-slim-bullseye - -FROM ${BASE_IMAGE} - -LABEL maintainer="Andrii Rieznik " - -LABEL org.opencontainers.image.source=https://github.com/andriyreznik/docker-python-gdal +LABEL org.opencontainers.image.authors=andrii.rieznik@pm.me +LABEL org.opencontainers.image.source=https://github.com/andrii-reznik/docker-python-gdal LABEL org.opencontainers.image.description="Debian based image with pre-installed GDAL/OGR libraries and Python bindings" LABEL org.opencontainers.image.licenses=MIT -ARG GDAL_VERSION=3.2.3 +ARG PYTHON_VERSION=3.12.4 +ARG GDAL_VERSION=3.9.1 ARG SOURCE_DIR=/usr/local/src/python-gdal +ENV PYENV_ROOT="/usr/local/pyenv" +ENV PATH="/usr/local/pyenv/shims:/usr/local/pyenv/bin:$PATH" + RUN \ -# Install runtime dependencies + # Install runtime dependencies apt-get update \ && apt-get install -y --no-install-recommends \ build-essential \ wget \ - automake libtool pkg-config libsqlite3-dev sqlite3 \ - libpq-dev \ - libcurl4-gnutls-dev \ - libproj-dev \ + git \ + libssl-dev \ + zlib1g-dev \ + libbz2-dev \ + libreadline-dev \ + libsqlite3-dev \ + libncursesw5-dev \ + xz-utils \ + tk-dev \ libxml2-dev \ - libgeos-dev \ - libnetcdf-dev \ - libpoppler-dev \ - libspatialite-dev \ - libhdf4-alt-dev \ - libhdf5-serial-dev \ - libopenjp2-7-dev \ + libxmlsec1-dev \ + libffi-dev \ + liblzma-dev \ + ca-certificates \ + \ + curl \ + cmake \ + libproj-dev \ + swig \ && rm -rf /var/lib/apt/lists/* \ - \ -# Install numpy - && pip install numpy \ -# Build against PROJ master (which will be released as PROJ 6.0) - && wget "http://download.osgeo.org/proj/proj-6.0.0.tar.gz" \ - && tar -xzf "proj-6.0.0.tar.gz" \ - && mv proj-6.0.0 proj \ - && echo "#!/bin/sh" > proj/autogen.sh \ - && chmod +x proj/autogen.sh \ - && cd proj \ - && ./autogen.sh \ - && CXXFLAGS='-DPROJ_RENAME_SYMBOLS' CFLAGS='-DPROJ_RENAME_SYMBOLS' ./configure --disable-static --prefix=/usr/local \ - && make -j"$(nproc)" \ - && make -j"$(nproc)" install \ - # Rename the library to libinternalproj - && mv /usr/local/lib/libproj.so.15.0.0 /usr/local/lib/libinternalproj.so.15.0.0 \ - && rm /usr/local/lib/libproj.so* \ - && rm /usr/local/lib/libproj.la \ - && ln -s libinternalproj.so.15.0.0 /usr/local/lib/libinternalproj.so.15 \ - && ln -s libinternalproj.so.15.0.0 /usr/local/lib/libinternalproj.so \ - \ -# Get latest GDAL source + # Install pyenv + && git clone https://github.com/pyenv/pyenv.git ${PYENV_ROOT} \ + && echo 'export PYENV_ROOT=/usr/local/pyenv' >> /root/.bashrc \ + && echo 'export PATH=/usr/local/pyenv/bin:$PATH' >> /root/.bashrc \ + && echo 'eval "$(pyenv init -)"' >> /root/.bashrc \ + && eval "$(pyenv init -)" && pyenv install ${PYTHON_VERSION} \ + && eval "$(pyenv init -)" && pyenv global ${PYTHON_VERSION} \ + && eval "$(pyenv init -)" && pip install --upgrade pip \ + && eval "$(pyenv init -)" && pip install numpy setuptools \ + # Install GDAL + && export CMAKE_BUILD_PARALLEL_LEVEL=`nproc --all` \ && mkdir -p "${SOURCE_DIR}" \ && cd "${SOURCE_DIR}" \ && wget "http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz" \ && tar -xvf "gdal-${GDAL_VERSION}.tar.gz" \ - \ -# Compile and install GDAL - && cd "gdal-${GDAL_VERSION}" \ - && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH \ - && ./configure \ - --with-python \ - --with-curl \ - --with-openjpeg \ - --without-libtool \ - --with-proj=/usr/local \ - && make -j"$(nproc)" \ - && make install \ + && cd gdal-${GDAL_VERSION} \ + && mkdir build \ + && cd build \ + && cmake .. \ + -DBUILD_PYTHON_BINDINGS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DPYTHON_INCLUDE_DIR=`python -c "import sysconfig; print(sysconfig.get_path('include'))"` \ + -DPYTHON_LIBRARY=`python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))"` \ + -DGDAL_PYTHON_INSTALL_PREFIX=`pyenv prefix` \ + && cmake --build . \ + && cmake --build . --target install \ && ldconfig \ - \ -# Install Python bindings as standalone module via pip - && pip install GDAL==${GDAL_VERSION} \ - && cd /usr/local \ - \ -# Clean up + # Clean-up && apt-get update -y \ && apt-get remove -y --purge build-essential wget \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* \ && rm -rf "${SOURCE_DIR}" -CMD python3 -V && pip -V && gdalinfo --version +CMD python -V && pip -V && gdalinfo --version diff --git a/Makefile b/Makefile index ccedc4f..bc74c3a 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,12 @@ -GDAL_VERSION ?= 3.2.3 -PYTHON_VERSION ?= 3.10.0 -BASE_IMAGE ?= python:$(PYTHON_VERSION)-slim-bullseye +GDAL_VERSION ?= 3.9.1 +PYTHON_VERSION ?= 3.12.4 DOCKER_REPO ?= andrejreznik/python-gdal IMAGE ?= $(DOCKER_REPO):py$(PYTHON_VERSION)-gdal$(GDAL_VERSION) image: docker build \ --build-arg GDAL_VERSION=$(GDAL_VERSION) \ - --build-arg BASE_IMAGE=$(BASE_IMAGE) \ - --no-cache \ + --build-arg PYTHON_VERSION=$(PYTHON_VERSION) \ -t $(IMAGE) . test: diff --git a/README.md b/README.md index 1a18b0c..a553d87 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # 🐳 python-gdal -![Build](https://img.shields.io/github/actions/workflow/status/andriyreznik/docker-python-gdal/push.yml?branch=master)![Pulls](https://img.shields.io/docker/pulls/andrejreznik/python-gdal.svg)![Size](https://img.shields.io/docker/image-size/andrejreznik/python-gdal/latest.svg) +![Build](https://img.shields.io/github/actions/workflow/status/andrii-reznik/docker-python-gdal/push.yml?branch=master)![Pulls](https://img.shields.io/docker/pulls/andrejreznik/python-gdal.svg)![Size](https://img.shields.io/docker/image-size/andrejreznik/python-gdal/latest.svg) #### Python + GDAL/OGR Docker image Get and compile the latest stable GDAL/OGR sources from official repository. @@ -15,9 +15,9 @@ $ docker run andrejreznik/python-gdal:stable Will output Python, pip and GDAL versions: ```console -Python 3.10.0 -pip 21.2.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10) -GDAL 3.2.3, released 2021/04/27 +Python 3.12.4 +pip 24.1.1 from /usr/local/pyenv/versions/3.12.4/lib/python3.12/site-packages/pip (python 3.12) +GDAL 3.9.1, released 2024/06/22 ``` Run container and start an interactive bash session as root @@ -37,5 +37,5 @@ $ docker run andrejreznik/python-gdal:py3.7.3-gdal3.0.0 or build your own image with passed build args ```bash -$ make image GDAL_VERSION=2.3.1 BASE_IMAGE=python:3.5-jessie +$ make image GDAL_VERSION=3.8.4 PYTHON_VERSION=3.11 ```