From 5277aa609f3acdda28c69a698b88aff278b4774d Mon Sep 17 00:00:00 2001 From: Oscar Utbult Date: Sun, 10 Jul 2022 19:13:50 +0200 Subject: [PATCH] Add Dockerfile linter --- Makefile | 1 + scripts/ci-lint-dockerfiles.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 scripts/ci-lint-dockerfiles.sh diff --git a/Makefile b/Makefile index ec2f01ce3c80..764f42358b31 100644 --- a/Makefile +++ b/Makefile @@ -443,6 +443,7 @@ lint: $(GOLANGCI_LINT) ## Lint the codebase $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) cd $(TEST_DIR); $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) cd $(TOOLS_DIR); $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) + ./scripts/ci-lint-dockerfiles.sh .PHONY: lint-fix lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter diff --git a/scripts/ci-lint-dockerfiles.sh b/scripts/ci-lint-dockerfiles.sh new file mode 100755 index 000000000000..3a87d57a989d --- /dev/null +++ b/scripts/ci-lint-dockerfiles.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2022 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +FILES=$(find -- * -name Dockerfile) +while read -r file; do + echo "Linting: ${file}" + # Configure the linter to only fail for errors. Can be set to: error | warning | info | style | ignore | none + docker run --rm -i ghcr.io/hadolint/hadolint:v2.10.0 hadolint --failure-threshold error - < "${file}" +done <<< "${FILES}"