Commit 24da256d authored by Peter Parente's avatar Peter Parente Committed by GitHub

Merge pull request #1123 from romainx/pre-commit

pre-commit hook + minor fixes
parents 4b07fcdc 455e10b6
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.23.0
hooks:
- id: yamllint
args: ['-d {extends: relaxed, rules: {line-length: disable}}', '-s']
files: \.(yaml|yml)$
- repo: https://github.com/openstack-dev/bashate.git
rev: 2.0.0
hooks:
- id: bashate
- repo: local
hooks:
- id: hadolint
name: Hadolint linter
description: Runs Hadolint to check for Dockerfile best practices
language: system
types:
- dockerfile
entry: hadolint
...@@ -25,6 +25,7 @@ ALL_IMAGES:=$(ALL_STACKS) ...@@ -25,6 +25,7 @@ ALL_IMAGES:=$(ALL_STACKS)
# Linter # Linter
HADOLINT="${HOME}/hadolint" HADOLINT="${HOME}/hadolint"
HADOLINT_VERSION="v1.18.0"
help: help:
# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html # http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
...@@ -73,7 +74,7 @@ dev/%: ## run a foreground container for a stack ...@@ -73,7 +74,7 @@ dev/%: ## run a foreground container for a stack
docker run -it --rm -p $(PORT):8888 $(DARGS) $(OWNER)/$(notdir $@) $(ARGS) docker run -it --rm -p $(PORT):8888 $(DARGS) $(OWNER)/$(notdir $@) $(ARGS)
dev-env: ## install libraries required to build docs and run tests dev-env: ## install libraries required to build docs and run tests
pip install -r requirements-dev.txt @pip install -r requirements-dev.txt
docs: ## build HTML documentation docs: ## build HTML documentation
make -C docs html make -C docs html
...@@ -131,11 +132,18 @@ lint-build-test-all: $(foreach I,$(ALL_IMAGES),lint/$(I) arch_patch/$(I) build/$ ...@@ -131,11 +132,18 @@ lint-build-test-all: $(foreach I,$(ALL_IMAGES),lint/$(I) arch_patch/$(I) build/$
lint-install: ## install hadolint lint-install: ## install hadolint
@echo "Installing hadolint at $(HADOLINT) ..." @echo "Installing hadolint at $(HADOLINT) ..."
@curl -sL -o $(HADOLINT) "https://github.com/hadolint/hadolint/releases/download/v1.18.0/hadolint-$(shell uname -s)-$(shell uname -m)" @curl -sL -o $(HADOLINT) "https://github.com/hadolint/hadolint/releases/download/$(HADOLINT_VERSION)/hadolint-$(shell uname -s)-$(shell uname -m)"
@chmod 700 $(HADOLINT) @chmod 700 $(HADOLINT)
@echo "Installation done!" @echo "Installation done!"
@$(HADOLINT) --version @$(HADOLINT) --version
pre-commit-all: ## run pre-commit hook on all files
@pre-commit run --all
pre-commit-install: ## set up the git hook scripts
@pre-commit --version
@pre-commit install
pull/%: DARGS?= pull/%: DARGS?=
pull/%: ## pull a jupyter image pull/%: ## pull a jupyter image
docker pull $(DARGS) $(OWNER)/$(notdir $@) docker pull $(DARGS) $(OWNER)/$(notdir $@)
......
# Image Lint # Lint
In order to enforce some rules **linters** are used in this project.
Linters can be run either during the **development phase** (by the developer) and during **integration phase** (by Travis).
To integrate and enforce this process in the project lifecycle we are using **git hooks** through [pre-commit][pre-commit].
## Pre-commit hook
### Installation
pre-commit is a Python package that needs to be installed.
This can be achieved by using the generic task used to install all Python development dependencies.
```sh
# Install all development dependencies for the project
$ make dev-env
# It can also be installed directly
$ pip install pre-commit
```
Then the git hooks scripts configured for the project in `.pre-commit-config.yaml` need to be installed in the local git repository.
```sh
$ make pre-commit-install
```
### Run
Now pre-commit (and so configured hooks) will run automatically on `git commit` on each changed file.
However it is also possible to trigger it against all files.
```sh
$ make pre-commit-all
```
## Image Lint
To comply with [Docker best practices][dbp], we are using the [Hadolint][hadolint] tool to analyse each `Dockerfile` . To comply with [Docker best practices][dbp], we are using the [Hadolint][hadolint] tool to analyse each `Dockerfile` .
## Installation ### Installation
There is a specific `make` target to install the linter. There is a specific `make` target to install the linter.
By default `hadolint` will be installed in `${HOME}/hadolint`. By default `hadolint` will be installed in `${HOME}/hadolint`.
...@@ -15,9 +50,9 @@ $ make lint-install ...@@ -15,9 +50,9 @@ $ make lint-install
# Haskell Dockerfile Linter v1.17.6-0-gc918759 # Haskell Dockerfile Linter v1.17.6-0-gc918759
``` ```
## Lint ### Linting
### Per Stack #### Per Stack
The linter can be run per stack. The linter can be run per stack.
...@@ -41,7 +76,7 @@ Optionally you can pass arguments to the linter. ...@@ -41,7 +76,7 @@ Optionally you can pass arguments to the linter.
$ make lint/scipy-notebook ARGS="--format codeclimate" $ make lint/scipy-notebook ARGS="--format codeclimate"
``` ```
### All the Stacks #### All the Stacks
The linter can be run against all the stacks. The linter can be run against all the stacks.
...@@ -49,7 +84,7 @@ The linter can be run against all the stacks. ...@@ -49,7 +84,7 @@ The linter can be run against all the stacks.
$ make lint-all $ make lint-all
``` ```
## Ignoring Rules ### Ignoring Rules
Sometimes it is necessary to ignore [some rules][rules]. Sometimes it is necessary to ignore [some rules][rules].
The following rules are ignored by default and sor for all images in the `.hadolint.yaml` file. The following rules are ignored by default and sor for all images in the `.hadolint.yaml` file.
...@@ -75,4 +110,5 @@ RUN cd /tmp && echo "hello!" ...@@ -75,4 +110,5 @@ RUN cd /tmp && echo "hello!"
[dbp]: https://docs.docker.com/develop/develop-images/dockerfile_best-practices [dbp]: https://docs.docker.com/develop/develop-images/dockerfile_best-practices
[rules]: https://github.com/hadolint/hadolint#rules [rules]: https://github.com/hadolint/hadolint#rules
[DL3006]: https://github.com/hadolint/hadolint/wiki/DL3006 [DL3006]: https://github.com/hadolint/hadolint/wiki/DL3006
[DL3008]: https://github.com/hadolint/hadolint/wiki/DL3008 [DL3008]: https://github.com/hadolint/hadolint/wiki/DL3008
\ No newline at end of file [pre-commit]: https://pre-commit.com/
\ No newline at end of file
docker docker
pre-commit
pytest pytest
recommonmark recommonmark
requests requests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment