Skip to content

Commit 7f7d700

Browse files
committed
feat: add dockerfiles linter - hadolint
1 parent fbe6abb commit 7f7d700

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ test-e2e: chainsaw # Run e2e tests against the K8s cluster specified in ~/.kube/
8787
$(CHAINSAW) test --values ./test/e2e/values.yaml
8888

8989
.PHONY: lint
90-
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar spell-lint ## Run all linters (suggest `make -k`)
90+
lint: golangci-lint.client golangci-lint.controller golangci-lint.sidecar spell-lint dockerfiles-lint ## Run all linters (suggest `make -k`)
9191
golangci-lint.%: golangci-lint
9292
cd $* && $(GOLANGCI_LINT) run $(GOLANGCI_LINT_RUN_OPTS) --config $(CURDIR)/.golangci.yaml --new
9393
spell-lint:
9494
git ls-files | grep -v -e CHANGELOG -e go.mod -e go.sum -e vendor | xargs $(SPELL_LINT) -i "Creater,creater,ect" -error -o stderr
95+
dockerfiles-lint:
96+
hack/tools/lint-dockerfiles.sh $(HADOLINT_VERSION)
9597

9698
.PHONY: lint-fix
9799
lint-fix: golangci-lint-fix.client golangci-lint-fix.controller golangci-lint-fix.sidecar ## Run all linters and perform fixes where possible (suggest `make -k`)
@@ -180,6 +182,7 @@ KIND_VERSION ?= v0.27.0
180182
KUSTOMIZE_VERSION ?= v5.6.0
181183
MDBOOK_VERSION ?= v0.4.47
182184
SPELL_LINT_VERSION ?= v0.6.0
185+
HADOLINT_VERSION ?= v2.12.0
183186

184187
.PHONY: chainsaw
185188
chainsaw: $(CHAINSAW)-$(CHAINSAW_VERSION)

hack/tools/lint-dockerfiles.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
5+
HADOLINT_VERSION=${1:-latest}
6+
7+
# Exclude vendor dependencies to avoid linting other Dockerfiles and prevent irrelevant warnings
8+
FILES=$(find . -path './vendor' -prune -o -name Dockerfile -print)
9+
10+
for file in $FILES; do
11+
echo "Linting Dockerfile: ${file}"
12+
${DOCKER:-docker} run --rm -i ghcr.io/hadolint/hadolint:"${HADOLINT_VERSION}" hadolint --failure-threshold warning - < "${file}"
13+
done

0 commit comments

Comments
 (0)