From 3364720f3435a7e5469e0f1ed0bce4c02e70af9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Tue, 5 Dec 2017 10:48:08 +0100 Subject: [PATCH] Validate Dockerfile indentation in pep8 Delegate code style validation to computers, they're better than human at it :) This commit adds a new `tools/validate-indentation.sh` script that errors when it finds an indented Dockerfile instruction, and enables the validation in the pep8 check. Also adjust the logic of `tools/validate-all-dockerfiles.sh` so that it doesn't stop on first errors but instead shows all of them. Fixes the remaining indentations in Dockerfiles. Change-Id: I53c0d38304cb4f6d64a5dfab67f70d69b3eae587 --- docker/helm-repository/Dockerfile.j2 | 8 ++++---- docker/ironic/ironic-pxe/Dockerfile.j2 | 4 ++-- tools/validate-all-dockerfiles.sh | 12 +++++++++--- tools/validate-indentation.sh | 12 ++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100755 tools/validate-indentation.sh diff --git a/docker/helm-repository/Dockerfile.j2 b/docker/helm-repository/Dockerfile.j2 index c3028f61d9..dfb2ebdc20 100644 --- a/docker/helm-repository/Dockerfile.j2 +++ b/docker/helm-repository/Dockerfile.j2 @@ -46,12 +46,12 @@ RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ RUN {{ macros.install_pip(helm_repository_pip_packages | customizable("pip_packages"), constraints = false) }} -ENV helm_arch={{ base_arch }} - {% if base_arch == 'x86_64' %} - ENV helm_arch=amd64 +ENV helm_arch=amd64 {% elif base_arch == 'aarch64' %} - ENV helm_arch=arm64 +ENV helm_arch=arm64 +{% else %} +ENV helm_arch={{ base_arch }} {% endif %} {% block helm_repository_install_kubernetes_helm %} diff --git a/docker/ironic/ironic-pxe/Dockerfile.j2 b/docker/ironic/ironic-pxe/Dockerfile.j2 index c319973e09..ada4b0e83e 100644 --- a/docker/ironic/ironic-pxe/Dockerfile.j2 +++ b/docker/ironic/ironic-pxe/Dockerfile.j2 @@ -16,7 +16,7 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build ] %} {% if base_arch == 'aarch64' %} - ENV ironic_arch=aarch64 +ENV ironic_arch=aarch64 {% set ironic_pxe_packages = ironic_pxe_packages + [ 'grub2-efi', 'grub2-efi-aa64-modules' @@ -41,7 +41,7 @@ RUN sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf \ 'syslinux' ] %} {% elif base_arch == 'aarch64' %} - ENV ironic_arch=aarch64 +ENV ironic_arch=aarch64 {% set ironic_pxe_packages = ironic_pxe_packages + [ 'grub-efi-arm64' ] %} diff --git a/tools/validate-all-dockerfiles.sh b/tools/validate-all-dockerfiles.sh index 5a39d24c04..a2b33ff105 100755 --- a/tools/validate-all-dockerfiles.sh +++ b/tools/validate-all-dockerfiles.sh @@ -3,9 +3,15 @@ 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 +RES=0 find docker -name Dockerfile.j2 -print0 | - xargs -0 tools/validate-install-command.sh || exit 1 + xargs -0 tools/validate-maintainer.sh || RES=1 +find docker -name Dockerfile.j2 -print0 | + xargs -0 tools/validate-install-command.sh || RES=1 + +find docker -name Dockerfile.j2 -print0 | + xargs -0 tools/validate-indentation.sh || RES=1 + +exit $RES diff --git a/tools/validate-indentation.sh b/tools/validate-indentation.sh new file mode 100755 index 0000000000..de2f20c6f8 --- /dev/null +++ b/tools/validate-indentation.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +RES=0 + +for dockerfile in "$@"; do + if grep -qE '^\s+[A-Z]+\s' "$dockerfile"; then + echo "ERROR: $dockerfile has indented Dockerfile instruction" >&2 + RES=1 + fi +done + +exit $RES