From: Sébastien Han Date: Tue, 16 May 2017 14:22:21 +0000 (+0200) Subject: ceph-docker-lint: add docker shellcheck X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a389b7f25bee665b0ce884e587f5b6040e77c3a5;p=ceph-build.git ceph-docker-lint: add docker shellcheck To run shellcheck with the -x option (Follow 'source' statements even when the file is not specified as input. By default, shellcheck will only follow files specified on the command line (plus /dev/null). This option allows following any file the script may source.) we need at least version 0.4.0. Unfortunately epel only provides a 0.3.X version. Fortunately, the container image provides the latest version which helps us running the tests. Signed-off-by: Sébastien Han --- diff --git a/ceph-docker-lint/build/build b/ceph-docker-lint/build/build index 76cb7c51..d18e713f 100755 --- a/ceph-docker-lint/build/build +++ b/ceph-docker-lint/build/build @@ -21,46 +21,40 @@ function generate_filelist(){ } function check(){ + local file while read -r filename; do - if [[ -z "$IGNORE_THESE_CODES" ]] - then - shellcheck "$filename"; - else - shellcheck -e "$IGNORE_THESE_CODES" "$filename"; - fi + pushd "$(dirname "$filename")" + file=$(basename "$filename") + chcon -t svirt_sandbox_file_t "$file" + docker run -v "$(pwd)"/"$file":/"$file" koalaman/shellcheck --external-sources --exclude "$IGNORE_THESE_CODES" /"$file" + popd done return $? } function main() { -# install some of our dependencies -if [ "${HUDSON_URL}" = "https://jenkins.ceph.com/" ] -then - sudo yum -y install epel-release - sudo yum -y install ShellCheck - sudo yum -y install jq - pull_request_id=${ghprbPullId:-$2} - workspace=${WORKSPACE:-$1} -else - if [[ ! -x $(which jq) ]] - then - echo 'install jq first' - exit 1 - fi - if [[ ! -x $(which shellcheck) ]] + # install some of our dependencies + if [ "${HUDSON_URL}" = "https://jenkins.ceph.com/" ] then - echo 'install shellcheck first' - exit 1 + sudo yum -y install epel-release + sudo yum -y install docker jq + pull_request_id=${ghprbPullId:-$2} + workspace=${WORKSPACE:-$1} + else + if ! command -v docker || ! command -v jq + then + echo "docker or jq is/are missing, install it/them" + exit 1 + fi + pull_request_id=${ghprbPullId:-$2} + workspace=${WORKSPACE:-$1} fi - pull_request_id=${ghprbPullId:-$2} - workspace=${WORKSPACE:-$1} -fi -pushd "$workspace/ceph-docker" -generate_filelist | check -popd -exit $? + pushd "$workspace/ceph-docker" + generate_filelist | check + popd + exit $? } main "$@"