From a679dee6ae3b760a8d81838de23c033be4510460 Mon Sep 17 00:00:00 2001 From: samiwelthomasHO <113512609+samiwelthomasHO@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:26:33 +0100 Subject: [PATCH] Add hadolint into git pre-commit hooks (#273) * Add docker lint pre-commit using hadolint * Only lint dockerfiles that change in the commit. --- .githooks/pre-commit | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 957e52be..8ae90446 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,6 +3,7 @@ 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) @@ -10,4 +11,13 @@ 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 \ No newline at end of file