koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.55k stars 1.78k forks source link

Add better documentation to koalaman/shellcheck Docker Hub page - borrow from @NLKNguyen please #1360

Open obscurerichard opened 6 years ago

obscurerichard commented 6 years ago

The issue #727 brought in a lightweight Dockerfile that works really well. Thanks @koalaman and @NLKNguyen for getting this done.

It would be super-nice if the lovely documentation explaining how to use the Docker container in thenlknguyen/alpine-shellcheck Docker hub page made it to the koalaman/shellcheck Docker hub page.

I was only able to use this successfully after reading @NLKNguyen's instructions on his Docker hub page. The key advice here is to mount the current working directory on /mnt, as in the very good instructions @NLKNguyen provided:

Use as CLI program

$ docker run --rm -it -v $(pwd):/mnt koalaman/shellcheck --version

But all of that documentation is really good and it would be great if it would get adapted and migrated to https://hub.docker.com/r/nlknguyen/alpine-shellcheck/

See This In Action

I was able to use this as part of a validation/linting script in https://github.com/ModusCreateOrg/devops-infra-demo that checks all the shell scripts for errors in CI. See the Jenkinsfile, bin/validate.sh, and bin/common.sh, where this gets used.

From the Jenkinsfile:

stage('Validate') {
    node {
        unstash 'src'
        wrap.call({
            // Validate packer templates, check branch
            sh ("./bin/validate.sh")
        })
    }
}

From bin/common.sh:

# Only use TTY for Docker if we detect one, otherwise
# this will balk when run in Jenkins
# Thanks https://stackoverflow.com/a/48230089
declare USE_TTY
test -t 1 && USE_TTY="-t" || USE_TTY=""

# ...

function get_docker_shellcheck() {
    # See https://hub.docker.com/r/nlknguyen/alpine-shellcheck/
    # and https://github.com/koalaman/shellcheck/issues/727
    echo "docker run --rm -i ${USE_TTY} -v $(pwd):/mnt koalaman/shellcheck"
}

From bin/validate.sh, :

# Credit to http://stackoverflow.com/a/246128/424301
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# ...

# shellcheck disable=SC1090
. "$DIR/common.sh"

# ...

echo "Linting shell scripts"
DOCKER_SHELLCHECK=$(get_docker_shellcheck)
# shellcheck disable=SC2046
$DOCKER_SHELLCHECK $(find . -name '*.sh') env.sh.sample
obscurerichard commented 3 days ago

This is still an issue, alas @koalaman & @NLKNguyen - could whoever controls the koalaman/shellcheck Docker hub page coordinate to improve it for usability?

koalaman commented 1 day ago

Indeed it is. Please try it again now!