This is a Dockerfile that allows the user to run a containerized version of sqlfluff by Alan Cruickshank. The image is rebuilt weekly thanks to Jenkins.
docker build -t sqlfluff .
docker pull wesleydeanflexion/sqlfluff
# mount and lint a file with locally-built image
docker run --rm -it -v $(pwd):/data sqlfluff filename.sql
# pipe a file to test with hosted image
docker run --rm -i wesleydeanflexion/sqlfluff - < filename.sql
This will start in the current directory and scan all *.sql
files
(case-insensitive) with the hosted sqlfluff image. The sed
statement
will convert any container-specific paths back to paths meaningful
to the host system.
docker run \
--entrypoint '' \
--rm \
--interactive \
--volume $(pwd):/data \
wesleydeanflexion/sqlfluff \
find . \
-iname "*.sql" \
-exec sqlfluff lint {} \; \
| sed -Ee "s|/data/\.|$(pwd)|g"
/data/
to find the file(s) provided-
as a filename to read from STDIN (for piping)For your convenience, you may include the following into your shell
configuration file (e.g., ~/.bashrc
):
# this is the alias
alias sqlfluff='docker run --rm -i -v$(pwd):/data sqlfluff'
# here's how to use the alias
cat filename.sql | sqlfluff -
sqlfluff filename.sql