From eb1bfc2c2e157e90a57f2a0f5186db0dea4c3909 Mon Sep 17 00:00:00 2001 From: "Swapnil Kulkarni (coolsvap)" Date: Tue, 17 May 2016 15:39:25 +0530 Subject: Add support to lint the install commands in Dockerfiles Change-Id: Icb47ba8b13b13889e28bb285321f11344400edc2 Closes-Bug:#1582618 --- tools/pre-commit-hook | 4 ++-- tools/validate-all-dockerfiles.sh | 11 +++++++++++ tools/validate-all-maintainer.sh | 7 ------- tools/validate-install-command.sh | 12 ++++++++++++ tox.ini | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100755 tools/validate-all-dockerfiles.sh delete mode 100755 tools/validate-all-maintainer.sh create mode 100755 tools/validate-install-command.sh diff --git a/tools/pre-commit-hook b/tools/pre-commit-hook index a3c45b757..be7bc6db3 100755 --- a/tools/pre-commit-hook +++ b/tools/pre-commit-hook @@ -37,8 +37,8 @@ echo "=== json checks ===" ${TOPLEVEL}/tools/validate-all-json.sh || RES=1 -echo "=== maintainer checks ===" +echo "=== dockerfile checks ===" -${TOPLEVEL}/tools/validate-all-maintainer.sh || RES=1 +${TOPLEVEL}/tools/validate-all-dockerfiles || RES=1 exit $RES diff --git a/tools/validate-all-dockerfiles.sh b/tools/validate-all-dockerfiles.sh new file mode 100755 index 000000000..5a39d24c0 --- /dev/null +++ b/tools/validate-all-dockerfiles.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") +cd "$(dirname "$REAL_PATH")/.." + +find docker -name Dockerfile.j2 -print0 | + xargs -0 tools/validate-maintainer.sh || exit 1 + +find docker -name Dockerfile.j2 -print0 | + xargs -0 tools/validate-install-command.sh || exit 1 + diff --git a/tools/validate-all-maintainer.sh b/tools/validate-all-maintainer.sh deleted file mode 100755 index 32ac477ee..000000000 --- a/tools/validate-all-maintainer.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") -cd "$(dirname "$REAL_PATH")/.." - -find docker -name Dockerfile.j2 -print0 | - xargs -0 tools/validate-maintainer.sh || exit 1 diff --git a/tools/validate-install-command.sh b/tools/validate-install-command.sh new file mode 100755 index 000000000..bc7409690 --- /dev/null +++ b/tools/validate-install-command.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +RES=0 + +for dockerfile in "$@"; do + if grep "apt-get install\|yum install" "$dockerfile"; then + echo "ERROR: $dockerfile has incorrectly formatted install command Should be in the form 'apt-get|yum -y install ...'" >&2 + RES=1 + fi +done + +exit $RES diff --git a/tox.ini b/tox.ini index d3cda4bc2..90af6ff70 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ commands = flake8 {posargs} {toxinidir}/tools/validate-all-json.sh {toxinidir}/tools/validate-all-yaml.sh - {toxinidir}/tools/validate-all-maintainer.sh + {toxinidir}/tools/validate-all-dockerfiles.sh [testenv:bandit] commands = bandit -r ansible/library dev docker kolla tests tools -- cgit v1.2.3