Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --load-extension to be set via environment variables #112

Closed
simonw opened this issue Nov 16, 2017 · 1 comment
Closed

Allow --load-extension to be set via environment variables #112

simonw opened this issue Nov 16, 2017 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Nov 16, 2017

This will make it easier to package up datasette in a Docker container with a bunch of pre-compiled extensions without the user having to remember to include all of the options every time.

Click has a mechanism for this: http://click.pocoo.org/5/options/#multiple-values-from-environment-values

@simonw simonw added this to the SQLite extensions edition milestone Nov 16, 2017
@simonw simonw closed this as completed in 03572ae Nov 17, 2017
@simonw
Copy link
Owner Author

simonw commented Nov 17, 2017

I tesed this by first building and running a container using the new
Dockerfile from #114:

docker build .
docker run -it -p 8001:8001 6c9ca7e29181 /bin/sh

Then I ran this inside the container itself:

apt update && apt-get install wget -y \
    && wget http://www.gaia-gis.it/spatialite-2.3.1/test-2.3.sqlite.gz \
    && gunzip test-2.3.sqlite.gz \
    && mv test-2.3.sqlite test23.sqlite \
    && datasette -h 0.0.0.0 test23.sqlite

I visited this URL to confirm I got an error due to spatialite not being
loaded:

http://localhost:8001/test23-c88bc35?sql=select+ST_AsText%28Geometry%29+from+HighWays+limit+1

Then I checked that loading it with --load-extension worked correctly:

datasette -h 0.0.0.0 test23.sqlite \
    --load-extension=/usr/lib/x86_64-linux-gnu/mod_spatialite.so

Then, finally, I tested it with the new environment variable option:

SQLITE_EXTENSIONS=/usr/lib/x86_64-linux-gnu/mod_spatialite.so \
    datasette -h 0.0.0.0 test23.sqlite

Running it with an invalid environment variable option shows an error:

$ SQLITE_EXTENSIONS=/usr/lib/x86_64-linux-gnu/blah.so datasette \
    -h 0.0.0.0 test23.sqlite
Usage: datasette -h [OPTIONS] [FILES]...

Error: Invalid value for "--load-extension": Path "/usr/lib/x86_64-linux-gnu/blah.so" does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant