-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dockerfile): minimizes docker image size and introduces new vers…
…ion of gdal which should enable the latest vector driver support
- Loading branch information
1 parent
5805d54
commit c2e0f36
Showing
2 changed files
with
27 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,43 @@ | ||
ARG PYTHON_VERSION=3.11 | ||
|
||
FROM docker.io/python:${PYTHON_VERSION}-slim-bookworm as base | ||
# Base image with GDAL and Python | ||
ARG GDAL_VERSION=3.9.0 | ||
FROM ghcr.io/osgeo/gdal:ubuntu-small-$GDAL_VERSION as base | ||
|
||
ARG [email protected] | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
FROM base as runner | ||
# Install libs | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
python3-pip python3-venv build-essential libpq-dev python3-dev && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /home/appuser | ||
ENV PIP_NO_CACHE_DIR=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PATH="/home/appuser/.local/bin:$PATH" | ||
ENV PYTHON_LIB="/home/appuser/.local/lib/python$PYTHON_VERSION/site-packages" | ||
|
||
# Install runtime dependencies | ||
RUN apt-get update \ | ||
&& apt-get -y upgrade \ | ||
&& apt-get --no-install-recommends -y install libpq5 gdal-bin \ | ||
&& apt-get -y autoremove \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV PATH="/home/appuser/venv/bin:$PATH" | ||
|
||
RUN python3 -m venv /home/appuser/venv && \ | ||
/home/appuser/venv/bin/pip install --no-cache-dir --upgrade pip setuptools wheel | ||
|
||
FROM ghcr.io/hotosm/tippecanoe:main as tippecanoe-builder | ||
COPY requirements.txt requirements.lock | ||
RUN /home/appuser/venv/bin/pip install --no-cache-dir -r requirements.lock | ||
|
||
FROM runner as with-tippecanoe | ||
COPY --from=tippecanoe-builder /usr/local/bin/tippecanoe* /usr/local/bin/ | ||
COPY --from=tippecanoe-builder /usr/local/bin/tile-join /usr/local/bin/ | ||
|
||
# Builder stage , python dependencies and project setup | ||
FROM base as python-builder | ||
# Copy application files | ||
COPY README.md setup.py pyproject.toml /home/appuser/ | ||
COPY API/ /home/appuser/API/ | ||
COPY src/ /home/appuser/src/ | ||
|
||
ENV PIP_NO_CACHE_DIR=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN /home/appuser/venv/bin/pip install --no-cache-dir . | ||
|
||
RUN apt-get update \ | ||
&& apt-get -y upgrade \ | ||
&& apt-get --no-install-recommends -y install \ | ||
build-essential libpq-dev libspatialite-dev libgdal-dev libboost-numpy-dev | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
RUN gdal-config --version | awk -F'[.]' '{print $1"."$2}' | ||
# Final image | ||
FROM ghcr.io/osgeo/gdal:ubuntu-small-$GDAL_VERSION | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install --user --no-cache-dir --upgrade pip setuptools wheel\ | ||
&& pip install --user --no-cache-dir GDAL=="$(gdal-config --version)" \ | ||
&& pip install --user --no-cache-dir -r requirements.txt | ||
|
||
FROM with-tippecanoe as prod | ||
COPY --from=python-builder /root/.local /home/appuser/.local | ||
WORKDIR /home/appuser | ||
RUN useradd --system --uid 900 --home-dir /home/appuser --shell /bin/false appuser && \ | ||
chown -R appuser:appuser /home/appuser | ||
|
||
RUN useradd --system --uid 900 --home-dir /home/appuser --shell /bin/false appuser \ | ||
&& chown -R appuser:appuser /home/appuser | ||
ENV PATH="/home/appuser/venv/bin:$PATH" | ||
COPY --from=base /home/appuser /home/appuser | ||
|
||
USER appuser | ||
|
||
# API and source code, changes here don't invalidate previous layers | ||
|
||
# Copy config.txt if you have your configuration setup in config | ||
# COPY config.txt . | ||
COPY README.md . | ||
COPY setup.py . | ||
COPY pyproject.toml . | ||
COPY API/ ./API/ | ||
COPY src/ ./src/ | ||
|
||
RUN python setup.py install --user | ||
|
||
CMD ["uvicorn", "API.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000", "--no-use-colors", "--proxy-headers"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ PyYAML==6.0.1 | |
flower==2.0.1 | ||
|
||
##duckdb | ||
duckdb==0.9.2 | ||
duckdb==1.0.0 | ||
|
||
##hdx | ||
hdx-python-api==6.2.8 | ||
|