Code Monkey home page Code Monkey logo

dockerfile_lint's Introduction

NPM Build Status

dockerfile-lint

A rule based 'linter' for Dockerfiles. The linter rules can be used to check file syntax as well as arbitrary semantic and best practice attributes determined by the rule file writer. The linter can also be used to check LABEL rules against docker images.

Table of Contents

Quickstart

  1. Change to directory where you have a Dockerfile
  2. run
  • Atomic CLI

        atomic run projectatomic/dockerfile-lint
    
        atomic run projectatomic/dockerfile-lint image <imageid>
    
  • Docker CLI

        docker run -it --rm -v $PWD:/root/ \
               projectatomic/dockerfile-lint \
               dockerfile_lint [-f Dockerfile]
    
        docker run -it --rm -v $PWD:/root/  \
               -v /var/run/docker.sock:/var/run/docker.sock \
               projectatomic/dockerfile-lint \
               dockerfile_lint  image <imageid>
    

By default, the linter runs in strict mode (errors and/or warnings result in non-zero return code). Run the command with -p or --permissive to run in permissive mode:

        atomic run projectatomic/dockerfile-lint -p

        docker run -it --rm -v $PWD:/root/ \
                           projectatomic/dockerfile-lint \
                           dockerfile_lint -p -f Dockerfile

Extending and Customizing: Rule Files

Rule files are written in yaml. See the example rule file sample_rules.yaml in the root folder of the project. The rules are implememented using regular expressions, run on one instruction of the dockerfile at a time. The rule file has 4 sections, a profile section, a general section, a line rule section and a required instruction section.

Profile Section

The profile section gives information about the rule file The information here is meant to help a user select a rule file that is appropriate for a given dockerfile. Example:

profile:
  name: "Default"
  description: "Default Profile. Checks basic syntax."

General Section

This section contains general syntax rules.

Rule Attributes

Here is an example of a line rule expressed in yaml:

    label: "is_latest_tag"
    regex: /latest/
    level: "info"
    inverse_rule: true
    message: "base image uses 'latest' tag"
    description: "using the 'latest' tag may cause unpredictable builds. It is recommended that a specific tag is used in the FROM line."
    reference_url:

Line Rule Section

This section contains rules that must be run on a given instruction in the dockerfile. There is a rule to check the syntax of each instruction and zero or more rules for semantic checks. The example below shows rules to run against the FROM instruction:

line_rules:
    FROM:
      paramSyntaxRegex: /.+/
      rules:
        -
          label: "is_latest_tag"
          regex: /latest/
          level: "info"
          message: "base image uses 'latest' tag"
          description: "using the 'latest' tag may cause unpredictable builds. It is recommended that a specific tag is used in the FROM line."
          reference_url:
            - "https://docs.docker.com/engine/reference/builder/"
            - "#from"
        -
          label: "no_tag"
          regex: /[:]/
          level: "warn"
          inverse_rule: true
          message: "No tag is used"
          description: "No tag is used"
          reference_url:
            - "https://docs.docker.com/engine/reference/builder/"
            - "#from"
        -
          label: "from_not_redhat"
          regex: /rhel|redhat*/
          inverse_rule: true
          level: "error"
          message: "Base Image is not from Red Hat"
          description: "Base Image must be from Red Hat"
          reference_url:

Note the (optional) inverse_rule attribute - this is just a convinient way to negate a regex rule - by default a rule is considered violated if it matches the regex pattern, but when 'inverse_rule' is set to 'true' the rule is violated if the line does not match the regex.

Required Instruction Section

This section includes a list of instructions that must exist in the dockerfile in order for it to be considered valid.

Inline Ignore Instructions

The user can tell dockerfile_lint to ignore a specific comand line inside a Dockerfile by placing a comment containing the word "dockerfile_lint" followed by the word "ignore", separated by a space, or a space and a dash/equals sign, above the command in the Dockerfile to be ignored.

# Add is required <for some previously approved reason documented here>
# dockerfile_lint - ignore
ADD http://example.com/big.tar.xz /usr/src/things/

The above inline ignore would cause dockerfile_lint to skip processing the ADD command that follows it. This allows the writing of strict rules in order to catch when best practices are not followed, while still being able to explicitly override the check on a case by case basis if a valid reason exists.

Library Usage

Node.js application use

Install from github from your application root directory:

npm install git+https://github.com/projectatomic/dockerfile_lint

Import and use the validator:

var fs = require('fs');
var rulefile = '/path/to/rulefile';
var DockerFileValidator = require('dockerfile_lint');
var validator = new DockerFileValidator(rulefile);
var result = validator.validate(dockerfile);

Command Line use

You can install the linter globally on your pc:

sudo npm install -g dockerfile_lint

Run the tool:

dockerfile_lint  -f /path/to/dockerfile  [-f /path/to/second/dockerfile]  [-r /path/to/rule/file]

A default rule file is used if no rule file is given.

You can also run the tool without installing it - just clone the source repository and run the tool from the bin directory :

git clone [email protected]:projectatomic/dockerfile_lint.git
cd dockerfile_lint/bin
chmod 555 dockerfile_lint
dockerfile_lint  -f /path/to/dockerfile  [ -r /path/to/rule/file]

To display results as JSON use the -j option:

dockerfile_lint  -j -f /path/to/dockerfile  [ -r /path/to/rule/file]

To display results as JUnit XML file use the -u option:

dockerfile_lint  -u -f /path/to/dockerfile  [ -r /path/to/rule/file]

Command Help:

dockerfile_lint  -h

Credits

The linter is based on https://github.com/aweiteka/dockerfile_checker

License

MIT

dockerfile_lint's People

Contributors

alexandruivan avatar alvin-huang avatar arthurzenika avatar aweiteka avatar clement87 avatar dav1x avatar dependabot[bot] avatar goldmann avatar judavi avatar jzb avatar karstenhopp avatar lostintangent avatar lphiri avatar lucas-c avatar miouge1 avatar nightwatchcyber avatar peterdavehello avatar ralph-saunders avatar rhatdan avatar robertdebock avatar romain-dartigues avatar rwngwn avatar srstevenson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockerfile_lint's Issues

dockerfile_lint fails to download dockerfile

Does dockerfile_lint support downloading Dockerfile through http ?
Bellow traceback seems like it should be able to do it, but something went wrong.

$docker run -it --rm --privileged -v pwd:/root/ -v /var/run/docker.sock:/var/run/docker.sock projectatomic/dockerfile-lint dockerfile_lint -f https://raw.githubusercontent.com/projectatomic/dockerfile_lint/master/Dockerfile

/opt/dockerfile_lint/bin/dockerfile_lint:99
downloadDockerfile(dockerfileLocation, function (dockerfile) {
^
ReferenceError: downloadDockerfile is not defined
at lintDockerFile (/opt/dockerfile_lint/bin/dockerfile_lint:99:9)
at Object. (/opt/dockerfile_lint/bin/dockerfile_lint:143:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3

Update hosted instance of linter

Red Hat hosts the linter. This should be kept up to date, including providing a set of profiles to select from in the drop-down menu. Given the recent re-design of rules (which result in "profiles") we may need to provide these as a multi-select checkbox element. Or we somehow bundle rules as "Profiles" behind the scenes.

cc @dav1x

Reduce package size

Package contains unnecessary directories and files - sample_rules, test, .travis.yml and others. I can do PR if your accept this issue.

FROM 'latest' check broken

I cannot get the is_latest_tag rule under FROM to trigger. Can someone show me a use case? or is it broken?

Cannot install 0.2.0 on my system - no such file or directory

Its works with 0.1.1, but not 0.2.0...

Any idea? NPM + Node version is up2date (LTS)

npm install dockerfile_lint
npm ERR! Linux 4.4.0-1-amd64
npm ERR! argv "/home/markus/tools/node-v4.4.3-linux-x64/bin/node" "/home/markus/bin/npm" "install" "dockerfile_lint"
npm ERR! node v4.4.3
npm ERR! npm  v3.8.6
npm ERR! path /home/markus/devel/docker/vimbadmin/node_modules/dockerfile_lint/bin/dockerimage_lint
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod

npm ERR! enoent ENOENT: no such file or directory, chmod '/home/markus/devel/docker/vimbadmin/node_modules/dockerfile_lint/bin/dockerimage_lint'
npm ERR! enoent ENOENT: no such file or directory, chmod '/home/markus/devel/docker/vimbadmin/node_modules/dockerfile_lint/bin/dockerimage_lint'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/markus/devel/docker/vimbadmin/npm-debug.log

USER support for ARG variable

The USER instruction in a Dockerfile supports the use of an ARG variable. However, dockerfile_lint complains that this is invalid. I took an example syntax from the Dockerfile reference found at https://docs.docker.com/engine/reference/builder/. Oh, and your reference below is no longer valid.

FROM busybox
USER ${user:-some_user}
ARG user
USER $user

Line 2: -> USER ${user:-some_user}
ERROR: Invalid parameters for command..
Reference -> https://docs.docker.com/reference/builder/

Support ARG instructions before FROM

As reported in Microsoft/vscode-docker#120, ARG instructions can now appear before the first FROM instruction so this shouldn't be flagged as an error by dockerfile_lint.

ARG CODE_VERSION=5.6-apache
FROM php:$CODE_VERSION
$ node bin\dockerfile_lint -f Dockerfile

--------ERRORS---------

Line 1: -> ARG CODE_VERSION=5.6-apache
ERROR: Missing or misplaced FROM.
Reference -> https://docs.docker.com/engine/reference/builder/


Line 2: -> FROM php:$CODE_VERSION
ERROR: Invalid parameters for command..
Reference -> https://docs.docker.com/engine/reference/builder/


ERROR: Required LABEL name/key 'Name' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project


ERROR: Required LABEL name/key 'Version' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project



--------INFO---------

INFO: There is no 'EXPOSE' instruction. Without exposed ports how will the service of the container be accessed?.
Reference -> https://docs.docker.com/engine/reference/builder/#expose


INFO: There is no 'CMD' instruction. None.
Reference -> https://docs.docker.com/engine/reference/builder/#cmd

Error: ENOENT: no such file or directory, open 'config/default_rules.yaml'

I am using dockerfile_lint as part of a Docker image I've built for all-in-one linting: https://github.com/singapore/lint-condo

Because of the project itself being a Docker image, I am using the npm version of your library.

I've experienced a confusing failure when upgrading from 0.2.2 to 0.2.3 in this PR: singapore/lint-condo#88

As above, the error is:

fs.js:549
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'config/default_rules.yaml'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at loadRuleFile (/node_modules/dockerfile_lint/lib/rulefile-loader.js:34:27)
    at load (/node_modules/dockerfile_lint/lib/rulefile-loader.js:74:9)
    at new Linter (/node_modules/dockerfile_lint/lib/linter.js:64:18)
    at lint (/node_modules/dockerfile_lint/bin/dockerfile_lint:84:25)
    at lintDockerFile (/node_modules/dockerfile_lint/bin/dockerfile_lint:104:9)
    at Object.<anonymous> (/node_modules/dockerfile_lint/bin/dockerfile_lint:144:5)
    at Module._compile (module.js:410:26)

The command run was simply: dockerfile_lint -f Dockerfile

I don't see any note about a breaking change in 0.2.3 or that a config file is mandatory in your README. perhaps your default config yaml files got left out of the npm package or something like that? I don't mind adding a config file if it's a new requirement but I've got a feeling that this wasn't intentional.

Remove MAINTAINER as a required instruction in the default rules

The MAINTAINER instruction will be deprecated in Docker 1.13, so I'm not sure whether it makes sense to mark it as a required instruction in the default rules, especially since it's purpose could already be satisfied with a LABEL.

I'd already found this rule to be a little too noisy to begin with, and I wonder whether the upcoming deprecation provides another reason to just remove it.

I'm happy to send out the PR, but I wanted to get your thoughts first.

CC @lphiri

Check remote Dockerfile via http

I would like to check remote Dockerfiles. The -f flag could point to local file or remote file. Example:

dockerfile_lint -f https://raw.githubusercontent.com/projectatomic/dockerfile_lint/master/Dockerfile

Exit code does not reflect result of Analyzing Dockerfile

The exit code in the latest version sha256:342aee0d1a5a94b1984f252e88ee46579868148e3d1a3f1a8b649d78e67dfa6a always appears to be 0 even when it prints out errors with the Dockerfile:

bash-4.2# dockerfile_lint

# Analyzing Dockerfile


--------ERRORS---------

Line 1: -> FROM sepulworld/aptly-cli:latest
ERROR: base image uses 'latest' tag. using the 'latest' tag may cause unpredictable builds. It is recommended that a specific tag is used in the FROM line or *-released which is the latest supported release..
Reference -> https://docs.docker.com/engine/reference/builder/#from


ERROR: Required LABEL name/key 'Name' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project


ERROR: Required LABEL name/key 'Version' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project



--------INFO---------

INFO: There is no 'EXPOSE' instruction. Without exposed ports how will the service of the container be accessed?.
Reference -> https://docs.docker.com/engine/reference/builder/#expose


INFO: There is no 'CMD' instruction. None.
Reference -> https://docs.docker.com/engine/reference/builder/#cmd


bash-4.2# echo $?
0

This means without parsing the output and looking for the word "error" or similar it cannot be used in a CI pipeline (well it can it just always passes).

This wasn't always the case, the image with the hash: sha256:8cb52b124c2802355001f7e05b91d2e382aaaab7d433c8147499b9b85b7eb91b worked fine and reported the correct exit code.

$ docker run -it --rm -v $PWD:/root/ projectatomic/dockerfile-lint@sha256:8cb52b124c2802355001f7e05b91d2e382aaaab7d433c8147499b9b85b7eb91b  /bin/bash
bash-4.2# dockerfile_lint

# Analyzing Dockerfile


--------ERRORS---------

Line 1: -> FROM sepulworld/aptly-cli:latest
ERROR: base image uses 'latest' tag. using the 'latest' tag may cause unpredictable builds. It is recommended that a specific tag is used in the FROM line or *-released which is the latest supported release..
Reference -> https://docs.docker.com/engine/reference/builder/#from


ERROR: Required LABEL name/key 'Name' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project


ERROR: Required LABEL name/key 'Version' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project



--------INFO---------

INFO: There is no 'EXPOSE' instruction. Without exposed ports how will the service of the container be accessed?.
Reference -> https://docs.docker.com/engine/reference/builder/#expose


INFO: There is no 'CMD' instruction. None.
Reference -> https://docs.docker.com/engine/reference/builder/#cmd


bash-4.2# echo $?
1

count: n instruction not enforced

In sample_rules.yaml it appears the count: 1 instruction is not used. For example, changing count to 2 doesn't impact the test.

    - 
      instruction: "USER"
      count: 2
      level: "warn"
      message: "No 'USER' instruction"
      description: "The process(es) within the container may run as root and RUN instructions my be run as root"
      reference_url: 
        - "https://docs.docker.com/reference/builder/"
        - "#user"

TypeError: helper.or is not a function

if the LABEL command is poorly formatted, get TypeError in lib/linter.js, line 27

function validateCommand(command, context, result) {
    if (command.error) {
        helper.or(result, command.lineno, command.raw, command.error,null);
    }

i think it should be addError:

helper.addError(result, command.lineno, command.raw, command.error,null);

To reproduce this issue, simply put the following in a dockerfile and run dockerfile_lint:

LABEL Nam

Modify container image to be more flexible

We should evaluate the use of this container image and create an entrypoint/cmd combination that works for all use cases.

  • interactive (run once) or shell environment?
  • Support alternate filenames to "Dockerfile".
  • Support passing in rule sets.

Not compatible with multistaged build

Unfortunately your linter does not seem compatible with multistaged build Dockerfile as the following log can show:

Line 1: -> FROM golang:1.10-alpine AS provider-aws
ERROR: Invalid parameters for command.. 
Reference -> https://docs.docker.com/engine/reference/builder/

It would be nice to still be able to use this linter with multistaged build Dockerfile...

FROM

The regex /^[\\w./-:]+(:[\\w.]+)?(-[\\w.]+)?$/ actually treats /-: as a range instead of 3 different characters. Instead It should be something like /^[\\w-./:]+(:[\\w.]+)?(-[\\w.]+)?$/.

Support multiple rules files

Is there a way to include multiple rules files such as -r /rules/ruleset1.yaml /rules/ruleset2.yaml? I think this would be useful if I wanted to add some custom rules for my organization that are in addition to the default ruleset for example.

If not, would this be a feature that other people would be interested in?

Add "--permissive" flag

We want to exit 1 on warning and error but provide a --permissive flag that would exit 1 only on error, exit 0 on warning.

Exit code is always 1

When using the linter via CLI the return code is always 1:

bash-4.3# ./node_modules/.bin/dockerfile_lint -f workspace/dock\ test\ build/standalone/eap/6.4/Dockerfile 
Check passed!
bash-4.3# echo $?                                                                                          
1
bash-4.3# ./node_modules/.bin/dockerfile_lint -f test

--------ERRORS---------

Line 6: -> ASDEXPOSE 8080
ERROR: Invalid instruction. Reference -> None


bash-4.3# echo $?                                    
1

This makes it unusable for automated tests.

Allow injection of SSL certificates or use npm set strict-ssl false as fallback

My own Git is protected by some custom SSL certificate. If I run

docker run -it --rm --privileged -v `pwd`:/root/ \                                                                             
           projectatomic/dockerfile-lint \
           dockerfile_lint -f 'https://my-github-repository/blob/master/Dockerfile'

npm is complaining about it not being able to verify the SSL certificate. Hence it would be nice if I could either inject SSL certificates, run a npm set strict-ssl false as fallback before the dockerfile_lint or having the work done in this PR fallback to an insecure HTTPS automatically. I could of course build my own image, but I imagine that I am not the only one with this usecase.

The latest release changed executable permissions

bin/dockerfile_lint 100755 โ†’ 100644

$ dockerfile_lint -f Dockerfile
/usr/bin/bash: line 47: /usr/bin/dockerfile_lint: Permission denied

If I change permissions for /opt/dockerfile_lint/bin/dockerfile_lint then it works

# chmod +x /opt/dockerfile_lint/bin/dockerfile_lint
[root@3d7b961bb3ec ~]# /usr/bin/dockerfile_lint

# Analyzing Dockerfile

Allow to pass several Dockerfiles with -f

Hi.

In order to better integrate this hook as a pre-commit hook, it would be very handy to allow for several file names to be passed as argument to the CLI.
A line indicating the file name analysed could be printed before each report, so the user does not get mixed up.

This does not seem very hard to implement, I can submit a PR if you agree with this idea.

The CLI command could then be callable like this: dockerfile_lint -f component1/Dockerfile component2/Dockerfile

Line numbers are off if \r\n is used

dockerfile_lint warns about errors being on lines 3 and 5 but it should really be on lines 2 and 3. It's not splitting the \r\n characters as a set.

image

> cat Dockerfile.test
FROM busybox
HEALTHCHECK cmd
HEALTHCHECK cmd
> node bin\dockerfile_lint -f Dockerfile.test

--------ERRORS---------

Line 3: -> HEALTHCHECK cmd
ERROR: A HEALTHCHECK instruction must specify either NONE, or a valid CMD and options.
Reference -> https://docs.docker.com/engine/reference/builder/


Line 5: -> HEALTHCHECK cmd
ERROR: A HEALTHCHECK instruction must specify either NONE, or a valid CMD and options.
Reference -> https://docs.docker.com/engine/reference/builder/


ERROR: Required LABEL name/key 'Name' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project


ERROR: Required LABEL name/key 'Version' is not defined.
Reference -> http://docs.projectatomic.io/container-best-practices/#_recommended_labels_for_your_project



--------INFO---------

INFO: There is no 'EXPOSE' instruction. Without exposed ports how will the service of the container be accessed?.
Reference -> https://docs.docker.com/engine/reference/builder/#expose


INFO: There is no 'CMD' instruction. None.
Reference -> https://docs.docker.com/engine/reference/builder/#cmd

Add in debug option that flattens includes

Currently, functionality that allows for nested includes inside the base rules set as such:

includes: another-yaml-file.yaml

We would like functionality added that flattens all the input rules lists to a single file to simply in case of debugging. Additionally, the flattened file should also add in a single variable if multiples were detected in multiple files. For example, VendorName is a listed value in 2 different files. The accepted value should be the when included in the flattened output file.

Thank you!

Description for rule "no_tag" is "lorem ipsum tar"

Currently in basic_rules_atomic.yaml, basic_rules.yaml, default_rules.yaml, openshift.yaml, osbs.yaml, the description for rule no_tag is "lorem ipsum tar".
It looks like a default description that was forgotten.

'yamlParser is not defined' error on latest docker image

According to docs it should be optional.

projectatomic/dockerfile-lint@sha256:379fba187c13e6f5a14e97405bb1f0d6b7fdfe5f806d876ce2240c1eda45a104
running dockerfile_lint -f dockerfile-dir/Dockerfile
/opt/dockerfile_lint/bin/dockerfile_lint:59
    console.log(yamlParser.dump(rules));
                ^

ReferenceError: yamlParser is not defined
    at Object.<anonymous> (/opt/dockerfile_lint/bin/dockerfile_lint:59:17)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

'Invalid instruction' for question mark in URL

Hello,

In Dockerfile I have a RUN instruction which downloads a file:

RUN wget --no-check-certificate 'https://github.com/user/repo/.../binary?raw=true'

I'm having the following error:

$ dockerfile_lint -f Dockerfile --verbose

debug: Checking command : RUN
debug: Checking command : RAW=TRUE";
debug: Checking command : RUN
debug: Checking command : ENTRYPOINT
--------ERRORS---------

Line 21: -> raw=true";
ERROR: Invalid instruction.
Reference -> https://docs.docker.com/reference/builder/

Am I correct saying that the ?raw is interpreted incorrectly as a instruction?
Would appreciate your advice.

Defined_namevals case sensitive

A defined label in a dockerfile that is defined as

LABEL name
will only match if the line is listed as below:

defined_namevals:
name:
valueRegex: /([\w]+)./

If the LABEL Name is used; the linter will throw an error about missing label.

Can we cast the value into upper or lower before matching the line to allow for either variation before the regex match starts?

Support parsing docker inspect as an input option

There is a lot of value to validating a built image since metadata inherited from its parent image is not visible from the Dockerfile. It occurred to me that the output of docker inspect could be run through the same rules engine.

While it would be great to just pass in an image name as an argument to the linter, I would be happy with stdin or reading from a file. Docker supports a robust goformat syntax that allows us to customize the data format. Below is a simple example that outputs json.

$ sudo docker inspect --format='{{json .Config}}' rhel7/rhel-tools | python -m json.tool
{
    "AttachStderr": false,
    "AttachStdin": false,
    "AttachStdout": false,
    "Cmd": [
        "/usr/bin/bash"
    ],
    "Domainname": "",
    "Entrypoint": null,
    "Env": [
        "container=docker",
        "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin"
    ],
    "Hostname": "",
    "Image": "18c92348de3686dfc369b5acd799b0538b54072279a130f56688510f6e6f9828",
    "Labels": {
        "Architecture": "x86_64",
        "Authoritative_Registry": "registry.access.redhat.com",
        "BZComponent": "rhel-tools-docker",
        "Build_Host": "rcm-img-docker02.build.eng.bos.redhat.com",
        "Name": "rhel7/rhel-tools",
        "RUN": "docker run -it --name NAME --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=NAME -e IMAGE=IMAGE -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host IMAGE",
        "Release": "16",
        "Vendor": "Red Hat, Inc.",
        "Version": "7.2",
        "architecture": "x86_64",
        "build-date": "2016-02-18T20:07:06.477734Z",
        "vcs-ref": "f2f06c6f776688378d5a512f1dd2a3c1b6ca0c2e",
        "vcs-type": "git"
    },
    "OnBuild": [],
    "OpenStdin": false,
    "StdinOnce": false,
    "Tty": false,
    "User": "",
    "Volumes": null,
    "WorkingDir": ""
}

npm install fails on enhanced_label_rule_support branch

Looks like the extendify addition is causing some issues:

npm ERR! git clone ssh://[email protected]/lphiri/extendify.git Cloning into bare repository '/root/.npm/_git-remotes/ssh-git-github-com-lphiri-extendify-git-16889689'...
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git Permission denied (publickey).
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git fatal: Could not read from remote repository.
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git Please make sure you have the correct access rights
npm ERR! git clone ssh://[email protected]/lphiri/extendify.git and the repository exists.
npm ERR! Error: Command failed: Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! at ChildProcess.exithandler (child_process.js:658:15)
npm ERR! at ChildProcess.emit (events.js:98:17)
npm ERR! at maybeClose (child_process.js:766:16)
npm ERR! at Socket. (child_process.js:979:11)
npm ERR! at Socket.emit (events.js:95:17)
npm ERR! at Pipe.close (net.js:466:12)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Linux 3.10.0-327.el7.x86_64
npm ERR! command "node" "/usr/bin/npm" "install"
npm ERR! cwd /root/git2/dockerfile_lint
npm ERR! node -v v0.10.36
npm ERR! npm -v 1.3.6
npm ERR! code 128
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /root/git2/dockerfile_lint/npm-debug.log
npm ERR! not ok code 0

I went ahead and changed the package.json to point to the regular registry:
"extendify": "git+ssh://[email protected]/lphiri/extendify.git",
to
"extendify": "1.0.0",

I'm not sure if you need a specific version. But upon the new build, i get various errors:

-> bin/dockerfile_lint -f Dockerfile -r sample_rules/label_rules.yaml
/Users/dphillip/git/dockerfile_lint/lib/linter-utils.js:22
rule.exists = false;
^
TypeError: Cannot assign to read only property 'exists' of LABEL

and

/root/git2/dockerfile_lint/lib/linter-utils.js:165
if (rules[i].hasOwnProperty(stripQuotes(key))) {
^
TypeError: Cannot call method 'hasOwnProperty' of undefined

Quoted label titles

lib/linter-utils.js:13
value = value.replace(/(^")|("$)/g, '');

if labels titles are quoted for instance

LABEL "Name"="quoted/title"

the linter errors out on the following line.

Allow to pass a directory for recursive search Dockerfiles

Can anyone add a feature for recursive search all Dockerfiles from a directory?
Same feature exists in many linters and its very useful when you have many Dockerfiles (as example more than 20).
Ideally a glob pattern support for file path than we can pass Dockerfiles from pattern.

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.