Skip to content

Commit

Permalink
Add Dockerfile linter
Browse files Browse the repository at this point in the history
  • Loading branch information
oscr committed Jul 11, 2022
1 parent 29495a2 commit 9cca44b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# Build the manager binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
# hadolint ignore=DL3006
FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/clusterctl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# Build the clusterctl binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
# hadolint ignore=DL3006
FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down
2 changes: 1 addition & 1 deletion docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

FROM maven:3-jdk-8

RUN apt-get update && apt-get install -y --no-install-recommends graphviz fonts-symbola fonts-wqy-zenhei && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends graphviz=2.42.2-5 fonts-symbola=2.60-1.1 fonts-wqy-zenhei=0.9.45-8 && rm -rf /var/lib/apt/lists/*
RUN wget -O /plantuml.jar http://sourceforge.net/projects/plantuml/files/plantuml.1.2019.6.jar/download

# By default, java writes a 'hsperfdata_<username>' directory in the work dir.
Expand Down
26 changes: 26 additions & 0 deletions scripts/ci-lint-dockerfiles.sh
Original file line number Diff line number Diff line change
@@ -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 fail for warnings and 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 warning - < "${file}"
done <<< "${FILES}"
5 changes: 5 additions & 0 deletions test/extension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# Build the extension binary
# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
# hadolint ignore=DL3006
FROM ${builder_image} as builder
WORKDIR /workspace

Expand Down
9 changes: 9 additions & 0 deletions test/infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

# Run this with docker build --build-arg builder_image=<golang:x.y.z>
ARG builder_image

# Ignore Hadolint rule "Always tag the version of an image explicitly."
# It's an invalid finding since the image is explicitly set in the Makefile.
# https://github.com/hadolint/hadolint/wiki/DL3006
# hadolint ignore=DL3006
FROM ${builder_image} as builder

# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
Expand Down Expand Up @@ -58,6 +63,10 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -trimpath -a -o /workspace/manager main.go

# NOTE: CAPD can't use non-root because docker requires access to the docker socket

# Ignore Hadolint rule "Using latest is prone to errors if the image will ever update. Pin the version explicitly to a release tag."
# https://github.com/hadolint/hadolint/wiki/DL3007
# hadolint ignore=DL3007
FROM gcr.io/distroless/static:latest

WORKDIR /
Expand Down

0 comments on commit 9cca44b

Please sign in to comment.