From 4a49b5952f0b7512635eda900abb9190b572321d Mon Sep 17 00:00:00 2001 From: grzesuav Date: Mon, 11 Mar 2019 18:06:30 +0100 Subject: [PATCH] Closes AdoptOpenJDK/openjdk-docker/issues#119 - Add hadolint for linting Dockerfiles --- .travis.yml | 4 +--- README.md | 2 ++ linter.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 linter.sh diff --git a/.travis.yml b/.travis.yml index ae1bf287..aa460eb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: sh -install: -- sudo apt-get update && sudo apt-get install --yes docker script: -- ./build_all.sh +- ./linter.sh diff --git a/README.md b/README.md index 228d08ba..06718e82 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ The Dockerfiles and associated scripts found in this project are licensed under # We should now have the proper manifest lists pushed to hub.docker.com to support multi-arch pulls. ``` +## Linting dockerfiles (via [hadolint](https://github.com/hadolint/hadolint)) +To lint generated dockerfiles run [./linter.sh](./linter.sh) - script will download hadolint binary and check all dockerfiles. # Info on other scripts ``` diff --git a/linter.sh b/linter.sh new file mode 100755 index 00000000..005f0a5d --- /dev/null +++ b/linter.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +################################################################################ +# 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 +# +# https://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. +################################################################################ + +################################################################################ +# +# This script downloads and executes hadolint. It will be run automatically +# by Travis on every push. You can run it manually to validate your changes. +# +################################################################################ + +set -eu + +hadolintDir="hadolint" +hadolintCmd="${hadolintDir}/hadolint" + +install() +{ + mkdir -p "${hadolintDir}" + + wget -O ${hadolintDir}/hadolint "https://github.com/hadolint/hadolint/releases/download/v1.16.0/hadolint-Linux-x86_64" + chmod +x "${hadolintCmd}" + "${hadolintCmd}" --version +} + +check() +{ + find . -name "Dockerfile*" -exec sh -c "./${hadolintCmd} {};echo " \; +} + +if [[ ! -d "${hadolintDir}" ]] ; then + install +fi +check