Sign inSign up

nlknguyen/alpine-shellcheck

By nlknguyen

Updated almost 9 years ago

Alpine with latest ShellCheck ---- Automated Build Weekly ---- Download size: 6 MB

Image
1

100K+

nlknguyen/alpine-shellcheck repository overview

Alpine-ShellCheck

Alpine Linux with ShellCheck -- a static analysis tool for shell scripts

The latest image is automated built weekly by Travis CI and is up-to-date with shellcheck repository. Tag version number is according to shellcheck released version.

Minimalist image size: 22 MB (download size is only 6 MB)

Include:

  • Alpine Linux (5 MB)
  • Shellcheck binary (16 MB)
  • Object dependencies (1 MB)

USAGE

Obtain the up-to-date image to your local cache: docker pull nlknguyen/alpine-shellcheck

Use as CLI program

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

ShellCheck - shell script analysis tool
version: 0.4.4
license: GNU General Public License, version 3
website: http://www.shellcheck.net

$ docker run --rm -it -v $(pwd):/mnt nlknguyen/alpine-shellcheck [input-file.sh]

Explain:

  • --rm remove the container after the program is terminated.
  • -it open an interactive terminal session (see -i -t for details)
  • -v $(pwd):/mnt mount the current directory to /mnt inside the container so that the container has access to the files in host machine. Also, /mnt is the working directory in the container, which is why it can see the files in the current host's directory right away.

The container's entry point is the shellcheck program, so you can pass arguments right into it just like any CLI program.

Set command alias

For more convenient, set command alias to run the image identically to a normal program

Example on most *NIX shells:

$ alias shellcheck='docker run --rm -it -v $(pwd):/mnt nlknguyen/alpine-shellcheck'

Now you can do something like $ shellcheck my-file.sh or setup your favorite linter in your code editor to invoke shellcheck automatically.

Depending on your shell, there is a conventional way to set alias permanently. Google for more information. The only thing to watch out is to not early evaluate $(pwd) by the time the alias is set, otherwise it always has a fixed path. The above example avoids that by using single quote instead of double.

Note: when you use the alias in some environment such as inside Vim, if you get this error "the input device is not a TTY", simply remove the -t tag from the Docker command (i.e. only keep -i)

On Docker for Windows, if you use Command Prompt (cmd.exe):

> DOSKEY shellcheck=docker run --rm -it -v %%cd%%:/mnt nlknguyen/alpine-shellcheck $*

%%cd%% will resolve into %cd% which is the current directory when the alias is called. $* means whatever arguments you pass into the alias command. For permanent result, follow this answer on StackOverflow to register the alias in the registry.

Use in Continuous Integration

Travis CI

Example .travis.yml

sudo: required

language: sh

services:
  - docker

before_install:
  - shopt -s expand_aliases  # allow alias
  - shopt -s globstar  # allow use of **

install:
  - docker pull nlknguyen/alpine-shellcheck
  - alias shellcheck='docker run --rm -it -v $(pwd):/mnt nlknguyen/alpine-shellcheck'

script:
  - shellcheck --version
  - shellcheck **/*.sh

Use as base image

This image is based on alpine:latest and only contains shellcheck, so you can derive from this without worrying about any unexpected difference from alpine:latest. For example:

FROM nlknguyen/alpine-shellcheck

MAINTAINER your name <[email protected]>

CMD ["ash"]

Shellcheck binary is located in /usr/local/bin, and a couple of object dependencies are in /usr/local/lib)

Tag summary

Content type

Image

Digest

Size

5.7 MB

Last updated

almost 9 years ago

docker pull nlknguyen/alpine-shellcheck