Skip to content

Commit

Permalink
Closes AdoptOpenJDK/openjdk-docker/issues#119 - Add hadolint for lint…
Browse files Browse the repository at this point in the history
…ing Dockerfiles
  • Loading branch information
grzesuav committed Apr 1, 2019
1 parent 8e8420e commit 4a49b59
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: sh
install:
- sudo apt-get update && sudo apt-get install --yes docker

script:
- ./build_all.sh
- ./linter.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
46 changes: 46 additions & 0 deletions linter.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4a49b59

Please sign in to comment.