Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Commit 3460a6b

Browse files
committed
A proof-of-concept docker pre-commit hook
0 parents  commit 3460a6b

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

‎Dockerfile‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu:xenial
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
5+
python3 \
6+
virtualenv && \
7+
apt-get clean
8+
9+
RUN virtualenv /venv -ppython3 && /venv/bin/pip install flake8
10+
ENV PATH=/venv/bin:$PATH
11+
12+
WORKDIR /src

‎README.md‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.

‎hooks.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- id: flake8-docker-not-for-production
2+
name: flake8 (via docker)
3+
description: flake8, but provided by docker
4+
entry: flake8
5+
language: docker
6+
files: \.py$

0 commit comments

Comments
 (0)