From bd30c696e18927207358ee9d63174a5c41c8297e Mon Sep 17 00:00:00 2001 From: Ravi Kotecha Date: Wed, 23 May 2018 18:43:34 +0100 Subject: [PATCH] Build Dockerfile with recent Sqlite + Spatialite (#280) Closes #278 ```bash $ docker run --rm -it datasette spatialite SpatiaLite version ..: 4.4.0-RC0 Supported Extensions: - 'VirtualShape' [direct Shapefile access] - 'VirtualDbf' [direct DBF access] - 'VirtualXL' [direct XLS access] - 'VirtualText' [direct CSV/TXT access] - 'VirtualNetwork' [Dijkstra shortest path] - 'RTree' [Spatial Index - R*Tree] - 'MbrCache' [Spatial Index - MBR cache] - 'VirtualSpatialIndex' [R*Tree metahandler] - 'VirtualElementary' [ElemGeoms metahandler] - 'VirtualKNN' [K-Nearest Neighbors metahandler] - 'VirtualXPath' [XML Path Language - XPath] - 'VirtualFDO' [FDO-OGR interoperability] - 'VirtualGPKG' [OGC GeoPackage interoperability] - 'VirtualBBox' [BoundingBox tables] - 'SpatiaLite' [Spatial SQL - OGC] PROJ.4 version ......: Rel. 4.9.3, 15 August 2016 GEOS version ........: 3.5.1-CAPI-1.9.1 r4246 TARGET CPU ..........: x86_64-linux-gnu the SPATIAL_REF_SYS table already contains some row(s) SQLite version ......: 3.23.1 Enter ".help" for instructions SQLite version 3.23.1 2018-04-10 17:39:29 Enter ".help" for instructions Enter SQL statements terminated with a ";" spatialite> ``` ```bash $ docker run --rm -it datasette python -c "import sqlite3; print(sqlite3.sqlite_version)" 3.23.1 ``` Also updates the query used to check for FTS5 as the old version wasn't detecting FTS5 for some reason. --- Dockerfile | 31 ++++++++++++++++++++++++++----- datasette/app.py | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 04c08d2c..cb3d6621 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,42 @@ FROM python:3.6-slim-stretch as build # Setup build dependencies -RUN apt update -RUN apt install -y python3-dev gcc libsqlite3-mod-spatialite +RUN apt update \ +&& apt install -y python3-dev build-essential wget libxml2-dev libproj-dev libgeos-dev libsqlite3-dev zlib1g-dev pkg-config \ + && apt clean + + +RUN wget "https://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz" && tar xzf sqlite-autoconf-3230100.tar.gz \ + && cd sqlite-autoconf-3230100 && ./configure --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1" \ + && make && make install + +RUN wget "https://www.gaia-gis.it/gaia-sins/freexl-1.0.5.tar.gz" && tar zxf freexl-1.0.5.tar.gz \ + && cd freexl-1.0.5 && ./configure && make && make install + +RUN wget "https://www.gaia-gis.it/gaia-sins/libspatialite-4.4.0-RC0.tar.gz" && tar zxf libspatialite-4.4.0-RC0.tar.gz \ + && cd libspatialite-4.4.0-RC0 && ./configure && make && make install + +RUN wget "https://www.gaia-gis.it/gaia-sins/readosm-1.1.0.tar.gz" && tar zxf readosm-1.1.0.tar.gz && cd readosm-1.1.0 && ./configure && make && make install + +RUN wget "https://www.gaia-gis.it/gaia-sins/spatialite-tools-4.4.0-RC0.tar.gz" && tar zxf spatialite-tools-4.4.0-RC0.tar.gz \ + && cd spatialite-tools-4.4.0-RC0 && ./configure && make && make install + + # Add local code to the image instead of fetching from pypi. -ADD . /datasette +COPY . /datasette RUN pip install /datasette FROM python:3.6-slim-stretch -# Copy python dependencies -COPY --from=build /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages +# Copy python dependencies and spatialite libraries +COPY --from=build /usr/local/lib/ /usr/local/lib/ # Copy executables COPY --from=build /usr/local/bin /usr/local/bin # Copy spatial extensions COPY --from=build /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu +ENV LD_LIBRARY_PATH=/usr/local/lib + EXPOSE 8001 CMD ["datasette"] diff --git a/datasette/app.py b/datasette/app.py index f6abe358..beefa108 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -256,7 +256,7 @@ class Datasette: for fts in ("FTS5", "FTS4", "FTS3"): try: conn.execute( - "CREATE VIRTUAL TABLE v{fts} USING {fts} (t TEXT)".format(fts=fts) + "CREATE VIRTUAL TABLE v{fts} USING {fts} (data)".format(fts=fts) ) fts_versions.append(fts) except sqlite3.OperationalError: