From c973d3abebe8e647ac0c00c97e03017520269eb8 Mon Sep 17 00:00:00 2001 From: Bertrand Roussel Date: Wed, 6 May 2020 05:33:25 -0700 Subject: [PATCH 1/3] Add option to run with Docker --- lint.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lint.sh b/lint.sh index 25850af..c7170f4 100755 --- a/lint.sh +++ b/lint.sh @@ -6,12 +6,19 @@ set -o nounset export PATH=$PATH:/usr/local/bin -if ! which hadolint &>/dev/null; then - >&2 echo 'hadolint command not found' - if [ -z "$(command -v brew)" ]; then - exit 1 +CMD="hadolint" + +if ! command -v hadolint >/dev/null; then + if [ -n "$(command -v brew)" ]; then + >&2 echo "hadolint: installing using brew" + brew install hadolint + elif [ -n "$(command -v docker)" ]; then + >&2 echo "hadolint: running with docker" + CMD="docker run --rm --volume=$PWD:$PWD:ro --workdir=$PWD hadolint/hadolint hadolint" + else + >&2 echo "hadolint: command not found and don't know how to install" fi - brew install hadolint fi -hadolint "$@" +set -x +$CMD "$@" From fa9019f4d986338c3449afc222ae5d6b6bd0e6c3 Mon Sep 17 00:00:00 2001 From: Bertrand Roussel Date: Wed, 6 May 2020 05:49:24 -0700 Subject: [PATCH 2/3] Add option to run directly on host --- .gitignore | 1 + lint.sh | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a90f63 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +hadolint diff --git a/lint.sh b/lint.sh index c7170f4..fb8019e 100755 --- a/lint.sh +++ b/lint.sh @@ -7,11 +7,21 @@ set -o nounset export PATH=$PATH:/usr/local/bin CMD="hadolint" +SCRIPT_DIR="$( cd `dirname "$0"` && pwd )" +export PATH="$SCRIPT_DIR:$PATH" if ! command -v hadolint >/dev/null; then if [ -n "$(command -v brew)" ]; then >&2 echo "hadolint: installing using brew" brew install hadolint + elif [ -n "$(command -v curl)" ]; then + VERSION="v1.17.6" + URL="https://github.com/hadolint/hadolint/releases/download/$VERSION/hadolint-$(uname)-x86_64" + if ! curl -fsSL "$URL" -o "$SCRIPT_DIR/hadolint"; then + >&2 echo "hadolint: unable to download from $URL" + exit 1 + fi + chmod +x "$SCRIPT_DIR/hadolint" elif [ -n "$(command -v docker)" ]; then >&2 echo "hadolint: running with docker" CMD="docker run --rm --volume=$PWD:$PWD:ro --workdir=$PWD hadolint/hadolint hadolint" From fd7dca7bc1b4739848e05011899037157b3862e4 Mon Sep 17 00:00:00 2001 From: Bertrand Roussel Date: Wed, 6 May 2020 05:55:07 -0700 Subject: [PATCH 3/3] Remove set -x --- lint.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/lint.sh b/lint.sh index fb8019e..f33317b 100755 --- a/lint.sh +++ b/lint.sh @@ -30,5 +30,4 @@ if ! command -v hadolint >/dev/null; then fi fi -set -x $CMD "$@"