Git Product home page Git Product logo

hadolint-wrapper's Introduction

PyPI version

hadolint-wrapper

What is hadolint?

Hadolint stands for Haskell Dockerfile Linter and is:

A smarter Dockerfile linter that helps you build best practice Docker images.

Example

Dockerfile

FROM debian
RUN export node_version="0.10" \
&& apt-get update && apt-get -y install nodejs="$node_verion"
COPY package.json usr/src/app
RUN cd /usr/src/app \
&& npm install node-static

EXPOSE 80000
CMD "npm start"

With hadolint

$ hadolint Dockerfile
Dockerfile:1 DL3006 Always tag the version of an image explicitly
Dockerfile:2 SC2154 node_verion is referenced but not assigned (did you mean 'node_version'?).
Dockerfile:2 DL3009 Delete the apt-get lists after installing something
Dockerfile:2 DL3015 Avoid additional packages by specifying `--no-install-recommends`
Dockerfile:5 DL3003 Use WORKDIR to switch to a directory
Dockerfile:5 DL3016 Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`
Dockerfile:8 DL3011 Valid UNIX ports range from 0 to 65535
Dockerfile:9 DL3025 Use arguments JSON notation for CMD and ENTRYPOINT arguments

With hadolint wrapper

hadolintw Dockerfile

sample-output

Installation

On OS X, the easiest way to install hadolintw is using Homebrew

brew install mikybars/tools/hadolint-wrapper

On other platforms, install hadolintw using pip

pip install hadolintw

Run from sources

If you happen to clone this repo and want to give it a try from the source code, the following command will do the job:

just run DOCKERFILE

Please note that in such case you will need some tools installed in your machine, namely just and Poetry.

Usage

$ hadolintw
Usage: hadolintw [OPTIONS] DOCKERFILE [HADOLINT_ARGS]...

  Provides a more clear output for hadolint

Options:
  -d, --use-docker             use the dockerized version of hadolint
  --color [never|auto|always]
  --help                       Show this message and exit.

Set up as a wrapper:

alias hadolint=hadolintw
hadolint Dockerfile --ignore DL3020
# Please note that all hadolint options must come AFTER the Dockerfile

FAQ

Does the wrapper keep the exit status of hadolint so that I can use it in my CI environment?

No problem.

My CI environment doesn't support colorized output. Can I disable it?

By default the wrapper can detect if the output is being written to a tty or a pipe or a file, enabling or disabling the color codes accordingly (—color auto is the default setting). However you can always turn this feature on or off regardless of the type of output destination:

hadolintw --color never Dockerfile

In our team we have a hadolint.yml with some rules defined for our project. Can we still use it with the hadolint wrapper?

Sure.

hadolintw Dockerfile --config hadolint.yml

The hadolint program is not available where my build is going to run but at least I have access to a Docker environment. Can I still run hadolint?

Be my guest.

$ hadolintw --use-docker Dockerfile
Unable to find image 'hadolint/hadolint:latest' locally
latest: Pulling from hadolint/hadolint
8a8460b25d70: Pulling fs layer
8a8460b25d70: Verifying Checksum
8a8460b25d70: Download complete
8a8460b25d70: Pull complete
Digest: sha256:0cdbd1e0f5fd3135d17617bb510a85c0248eb70b041021fe5431d4d1501d41b9
Status: Downloaded newer image for hadolint/hadolint:latest
...

hadolint-wrapper's People

Contributors

mikybars avatar

Stargazers

Malcolm Jones (bossjones/Tony Dark) avatar Islam Elsayed avatar Liam Pieri avatar Kristian Thy avatar ddelange avatar

Watchers

James Cloos avatar  avatar

hadolint-wrapper's Issues

hadolint: binary not found in $PATH

Installed hadolintw==1.2.1 using pip

Showing help works

hadolintw --help
Usage: hadolintw [OPTIONS] DOCKERFILE [HADOLINT_ARGS]...

  Pretty output for hadolint

Options:
  -d, --use-docker             use the dockerized version of hadolint
  --color [never|auto|always]
  --help                       Show this message and exit.

Trying to lint a Dockerfile does not

hadolintw Dockerfile
hadolint: binary not found in $PATH

Which binary is this refering to?

TypeError: __init__() got an unexpected keyword argument 'capture_output'

Python 3.6.8 (default, Apr  2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CentOS Linux release 7.8.2003 (Core)
Linux 3.10.0-1127.8.2.el7.x86_64
virtualenv 15.1.0
pip 20

# pip list
click      7.1.2
hadolintw  1.2.0
pip        20.1.1
setuptools 28.8.0
wheel      0.29.0

Traceback (most recent call last):
  File "/home/repo/venv/bin/hadolintw", line 11, in <module>
    sys.exit(main())
  File "/home/repo/venv/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/repo/venv/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/repo/venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/repo/venv/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/repo/venv/lib/python3.6/site-packages/hadolintw/main.py", line 73, in main
    process = subprocess.run(cmd, input=input_bytes, capture_output=True)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.