Skip to content

Commit

Permalink
Add hadolint into git pre-commit hooks (#273)
Browse files Browse the repository at this point in the history
* Add docker lint pre-commit using hadolint

* Only lint dockerfiles that change in the commit.
  • Loading branch information
samiwelthomasHO authored Oct 10, 2022
1 parent 0e711e2 commit a679dee
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
set -e

JSONNET_FILES_CHANGED=$(git --no-pager diff --cached --name-only --diff-filter=ACM | grep "sonnet" | wc -l)
DOCKERFILE_CHANGED=$(git --no-pager diff --cached --name-only --diff-filter=ACM | grep "Dockerfile" | wc -l)

REPO_ROOT_DIR=$(git rev-parse --show-toplevel)

if [ "$JSONNET_FILES_CHANGED" -gt "0" ]; then
$REPO_ROOT_DIR/monitoring-as-code/fmt.sh
$REPO_ROOT_DIR/monitoring-as-code/lint.sh
git add $REPO_ROOT_DIR
fi

if [ "$DOCKERFILE_CHANGED" -gt "0" ]; then
dockerfiles_changed=$(git --no-pager diff --cached --name-only --diff-filter=ACM | grep "Dockerfile")
for dockerfile in $dockerfiles_changed
do
echo $dockerfile
docker run --rm -i ghcr.io/hadolint/hadolint < $dockerfile
done
fi

0 comments on commit a679dee

Please sign in to comment.