Skip to content

Commit

Permalink
feat: debian bookworm
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-rieznik committed Jun 28, 2024
1 parent 6ae6e45 commit bebc3ad
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 91 deletions.
157 changes: 76 additions & 81 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,89 +1,84 @@
##
# 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 <andrii.rieznik@protonmail.com>"

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

RUN \
# 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 \
libxml2-dev \
libgeos-dev \
libnetcdf-dev \
libpoppler-dev \
libspatialite-dev \
libhdf4-alt-dev \
libhdf5-serial-dev \
libopenjp2-7-dev \
&& 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
&& 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 \
&& ldconfig \
\
# Install Python bindings as standalone module via pip
&& pip install GDAL==${GDAL_VERSION} \
&& cd /usr/local \
\
# 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}"
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# Python
git \
wget \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
ca-certificates \
# GDAL
curl \
cmake \
libproj-dev \
swig && \
# python3 python3-pip python3-numpy proj-bin
rm -rf /var/lib/apt/lists/*

ENV PYENV_ROOT="/usr/local/pyenv"
ENV PATH="/usr/local/pyenv/shims:/usr/local/pyenv/bin:$PATH"

# Build Python via pyenv
# RUN curl https://pyenv.run | bash
RUN 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

# Get latest GDAL source # compile and install GDAL
RUN 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" && \
cd gdal-${GDAL_VERSION} && \
mkdir build && \
cd build && \
cmake .. \
-DBUILD_PYTHON_BINDINGS=ON \
-DCMAKE_BUILD_TYPE=Release && \
# -DPYTHON_INCLUDE_DIR=/usr/local/pyenv/versions/3.12.4/include/python3.12 \
# -DPYTHON_LIBRARY=/usr/local/pyenv/versions/3.12.4/lib \
# -DPYTHON_EXECUTABLE:FILEPATH=`which python` && \
cmake --build . && \
cmake --build . --target install && \
ldconfig

# RUN \
# # Install Python bindings as standalone module via pip
# # && pip install GDAL==${GDAL_VERSION} \
# && cd /usr/local \
# \
# # 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
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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
```

0 comments on commit bebc3ad

Please sign in to comment.