|
| 1 | +pre-commit-docker-flake8 |
| 2 | +======================== |
| 3 | + |
| 4 | +## What is this? |
| 5 | + |
| 6 | +This is a proof-of-concept of providing a [pre-commit](http://pre-commit.com) |
| 7 | +hook for flake8 via docker. It is suggested to instead use flake8 as provided |
| 8 | +by [pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks) as |
| 9 | +you'll have slightly better performance and more control over the python |
| 10 | +executable. |
| 11 | + |
| 12 | +## How does this work? |
| 13 | + |
| 14 | +A few key lines in the `Dockerfile` make this work: |
| 15 | + |
| 16 | +```dockerfile |
| 17 | +WORKDIR /src |
| 18 | +``` |
| 19 | + |
| 20 | +`pre-commit` by convention mounts the user's code at `/src` inside the |
| 21 | +container. The executable is fed relative path filename arguments. The hook |
| 22 | +may make changes to the files as the source is mounted read-only and the |
| 23 | +executables are run as the user |
| 24 | + |
| 25 | + |
| 26 | +```dockerfile |
| 27 | +RUN virtualenv /venv -ppython3 && /venv/bin/pip install flake8 |
| 28 | +ENV PATH=/venv/bin:$PATH |
| 29 | +``` |
| 30 | + |
| 31 | +This creates a virtual environment inside the docker image and puts the |
| 32 | +virtualenv on the `PATH` so executables (such as `flake8`) can be run. |
| 33 | + |
| 34 | +Lastly, the metadata in hooks.yaml hooks this up: |
| 35 | + |
| 36 | +```yaml |
| 37 | + entry: flake8 |
| 38 | + language: docker |
| 39 | +``` |
| 40 | +
|
| 41 | +Here `flake8` is the executable inside the repository and we tell |
| 42 | +`pre-commit` that the language is `docker`. |
| 43 | + |
| 44 | + |
| 45 | +## How would I use this repository with pre-commit? |
| 46 | + |
| 47 | +Well, you probably wouldn't (and the hook has been labeled as such) but if you |
| 48 | +really wanted to you could add this to your `.pre-commit-config.yaml`: |
| 49 | + |
| 50 | +```yaml |
| 51 | +- repo: git://github.com/pre-commit/pre-commit-docker-flake8 |
| 52 | + sha: '' # Fill this in with a current revision |
| 53 | + hooks: |
| 54 | + - id: flake8-docker-not-for-production |
| 55 | +``` |
| 56 | + |
| 57 | +You'll also need to use at least version 0.10.0 of pre-commit. |
0 commit comments