dinedal / textql

Execute SQL against structured text like CSV or TSV
MIT License
9.05k stars 300 forks source link

reduce docker image to 19MB #96

Closed yuanyangwu closed 6 years ago

yuanyangwu commented 6 years ago

fix #95

Reduce docker image from 300MB to 19MB

Dockerfile.alpine requires Docker 17.05 or higher for it uses multi-stage build. Refer to docker installation for how to install it.

Details design document in https://github.com/yuanyangwu/yuanyangwu.github.io/blob/master/_posts/2018-05-22-minimize-textql-docker-image.md

Test

# build image
vagrant@ubuntu-xenial:~/textql$ sudo docker build -f Dockerfile.alpine -t textql:alpine .

# new image size is 19MB
vagrant@ubuntu-xenial:~/textql$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
textql              alpine              f800704c4c9d        3 minutes ago       18.8MB

# csv file
vagrant@ubuntu-xenial:~/textql$ cat test.csv
first_name,last_name,ssn
John,Barry,123456
Kathy,Smith,687987
Bob,McCornick,3979870

# test "-sql"
vagrant@ubuntu-xenial:~/textql$ sudo docker run --rm -it -v $(pwd):/tmp textql:alpine -header -sql 'SELECT * FROM test' test.csv
John,Barry,123456
Kathy,Smith,687987
Bob,McCornick,3979870

# test "-console"
vagrant@ubuntu-xenial:~/textql$ sudo docker run --rm -it -v $(pwd):/tmp textql:alpine -header -console test.csv
SQLite version 3.21.0 2017-10-24 18:55:49
Enter ".help" for usage hints.
sqlite> SELECT * FROM test;
John|Barry|123456
Kathy|Smith|687987
Bob|McCornick|3979870
sqlite> SELECT * FROM test WHERE ssn>200000;
Kathy|Smith|687987
Bob|McCornick|3979870
sqlite>