From afa435ac4f61fefc5930076a7becf99856f811e0 Mon Sep 17 00:00:00 2001 From: Samiwel Thomas Date: Tue, 4 Oct 2022 11:05:26 +0100 Subject: [PATCH] Add docker lint pre-commit using hadolint --- .githooks/pre-commit | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 957e52be..36361b0a 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,8 @@ 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 + find $REPO_ROOT_DIR -name Dockerfile -exec sh -c "echo {} && docker run --rm -i ghcr.io/hadolint/hadolint < {}" \; fi \ No newline at end of file