Super-linter: Hadolint checker ignores .hadolint.yaml config file

Created on 21 Aug 2020  路  17Comments  路  Source: github/super-linter

Describe the bug
I have a .hadolint.yaml inside my directory, but when I run super-linter (locally / remotely) it ignores this config file. According hadolint README, this config file should be used by default if exists: https://github.com/hadolint/hadolint#configure

To Reproduce

See the commands:

$ cat .hadolint.yaml
ignored:
  # Pin versions in apk add
  - DL3018
  # Pin versions in npm
  - DL3016

$ docker run -e RUN_LOCAL=true -v ${PWD}:/tmp/lint github/super-linter
...
2020-08-21 07:05:00 [INFO  ]   ----------------------------------------------
2020-08-21 07:05:00 [INFO  ]   ----------------------------------------------
2020-08-21 07:05:00 [INFO  ]   Linting [DOCKERFILE_HADOLINT] files...
2020-08-21 07:05:00 [INFO  ]   ----------------------------------------------
2020-08-21 07:05:00 [INFO  ]   ----------------------------------------------
2020-08-21 07:05:00 [INFO  ]   ---------------------------
2020-08-21 07:05:00 [INFO  ]   File:[/tmp/lint/Dockerfile]
2020-08-21 07:05:01 [ERROR ]   Found errors in [hadolint] linter!
2020-08-21 07:05:01 [ERROR ]   [/tmp/lint/Dockerfile:17 DL3018 Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
/tmp/lint/Dockerfile:17 DL3016 Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`]
2020-08-21 07:05:01 [ERROR ]   Linter CMD:[hadolint -c /action/lib/.automation/.hadolint.yml /tmp/lint/Dockerfile]
2020-08-21 07:05:01 [INFO  ]
...

If I run hadolint locally, the .hadolint.yaml is used by default:

$ hadolint Dockerfile ; echo $?
0

Expected behavior
super-linter should use .hadolint.yaml by default (if it exists) like described in hadolint README.

bug

All 17 comments

@ruzickap Hey, I think the way the super-linter runs, that file will need to be in the .github/linters/.hadolint.yml. If the file is in that location, it will pick it up at the run time and use it... Can you validate that?

I can confirm at least locally that @admiralAwkbar is correct, the config is found if placed in that location.

Now why are there two Dockerfile linters being run and where do we control the other one? :facepalm:

I can confirm at least locally that @admiralAwkbar is correct, the config is found if placed in that location.

Now why are there _two_ Dockerfile linters being run and where do we control the _other_ one? 馃う

We implement more than one linter to let the users choose which they want to use.
You can use VALIDATE_DOCKERFILE and VALIDATE_DOCKERFILE_HADOLINT to control this.

With both on by default? When both of them are opinionated and strict? May defaulting one or the other to off would be smarter.

All linters are run by default to let the user a ready to go config, and then users can customize as they se fit.

Thank you - yes I do have the .hadolint.yml in root of the git repo.

Is there any chance to configure super-linter to take config files also from the "top/root" of the git repository?

If I use the linters like hadolint, ansible-lint, markdownlint, yamllint (and many more) it's common practice to put their config files to the "top/root" of the git repository.

Maybe it would be handy to configure super-linter to look for configfiles for both locations:

  • Fist: ./.github/linters/
  • Second: ./

Thank you...

@ruzickap as stated in the readme, you can use LINTER_RULES_PATH to define where super-linter looks for this.

Yeah ... That's right, but super-linter looks for file called .hadolint.yml and the original hadolint (https://github.com/hadolint/hadolint#configure) looks for .hadolint.yaml.

Is there any way how I can specify the config file for specific linter?

If I set the LINTER_RULES_PATH: . it will not find the default config file .hadolint.yaml for hadolint like in case I run hadolint from command line:

$ ls -la .hadolint.yaml
.rw-rw-r-- 48 pruzicka 15 Jul 22:26 .hadolint.yaml

$ hadolint Dockerfile
$ 
$ docker run -e RUN_LOCAL=true -e LINTER_RULES_PATH=. -v ${PWD}:/tmp/lint github/super-linter:v3
...
[ERROR ]   [/tmp/lint/Dockerfile:26 DL3018 Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`]

$ mv .hadolint.yaml .hadolint.yml
$ hadolint Dockerfile
Dockerfile:26 DL3018 Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
$ docker run -e RUN_LOCAL=true -e LINTER_RULES_PATH=. -v ${PWD}:/tmp/lint github/super-linter:v3
...
[NOTICE]   All file(s) linted successfully with no errors detected

$ hadolint -c .hadolint.yml Dockerfile
$

Now both tools super-linter and hadolint are using different config files by default - .hadolint.yml vs .hadolint.yaml

super-linter internally uses hadolint then it will be nice if it can also use the .hadolint.yaml like the official hadolint to keep backward compatibility.

I think this is wrongfully closed, see my comment on PR #623 which I think only went part of the way.

I agree - this should not be closed.

The linter component of super-linter (whatever it is: hadolint, yamllint, ansible-lint, ...) should always look for the default config file (.hadolint.yaml, .yamllint.yml, .ansible-lint, ...) and then for specific file located in .github/linters.

Pinging @admiralAwkbar, please re-evaluate this closure.

This issue bit me as well :(

I do have an hadolint.yaml in my root, and set both DEFAULT_WORKSPACE and LINTER_RULES_PATH accordingly. Other rule files are being evaluated. Maybe there's an issue with yml vs yaml extension in linter.sh?

super-linter config:

    - id: 'super-linter'
      name: "github/super-linter:v3.9.3"
      env:
        - ACTIONS_RUNNER_DEBUG=true
        - ANSIBLE_DIRECTORY=configuration/ansible
        - DEFAULT_WORKSPACE=/workspace
        - DISABLE_ERRORS=false
        - LINTER_RULES_PATH=.
        # Disable multiple status reporting to avoid reporting any status
        # (see the if condition in super-linter/lib/linter.sh)
        - MULTI_STATUS=false
        - RUN_LOCAL=true
        - VALIDATE_ALL_CODEBASE=true

Log output:

Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]   ---------------------------------------------
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.ansible-lint.yml], using Default rules at:[/action/lib/.automation/.ansible-lint.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.arm-ttk.psd1], using Default rules at:[/action/lib/.automation/.arm-ttk.psd1]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.cfnlintrc.yml], using Default rules at:[/action/lib/.automation/.cfnlintrc.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.coffee-lint.json], using Default rules at:[/action/lib/.automation/.coffee-lint.json]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.stylelintrc.json], using Default rules at:[/action/lib/.automation/.stylelintrc.json]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./analysis_options.yml], using Default rules at:[/action/lib/.automation/analysis_options.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [INFO  ]   ----------------------------------------------
Step #0 - "super-linter": 2020-09-08 12:04:40 [INFO  ]   User provided file:[.dockerfilelintrc], setting rules file...
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.hadolint.yml], using Default rules at:[/action/lib/.automation/.hadolint.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.golangci.yml], using Default rules at:[/action/lib/.automation/.golangci.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.groovylintrc.json], using Default rules at:[/action/lib/.automation/.groovylintrc.json]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.htmlhintrc], using Default rules at:[/action/lib/.automation/.htmlhintrc]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./sun_checks.xml], using Default rules at:[/action/lib/.automation/sun_checks.xml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.eslintrc.yml], using Default rules at:[/action/lib/.automation/.eslintrc.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.chktexrc], using Default rules at:[/action/lib/.automation/.chktexrc]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.luacheckrc], using Default rules at:[/action/lib/.automation/.luacheckrc]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.markdown-lint.yml], using Default rules at:[/action/lib/.automation/.markdown-lint.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./phpcs.xml], using Default rules at:[/action/lib/.automation/phpcs.xml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./phpstan.neon], using Default rules at:[/action/lib/.automation/phpstan.neon]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./psalm.xml], using Default rules at:[/action/lib/.automation/psalm.xml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.powershell-psscriptanalyzer.psd1], using Default rules at:[/action/lib/.automation/.powershell-psscriptanalyzer.psd1]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.python-lint], using Default rules at:[/action/lib/.automation/.python-lint]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.flake8], using Default rules at:[/action/lib/.automation/.flake8]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.python-black], using Default rules at:[/action/lib/.automation/.python-black]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.lintr], using Default rules at:[/action/lib/.automation/.lintr]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.ruby-lint.yml], using Default rules at:[/action/lib/.automation/.ruby-lint.yml]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.sql-config.json], using Default rules at:[/action/lib/.automation/.sql-config.json]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.tflint.hcl], using Default rules at:[/action/lib/.automation/.tflint.hcl]
Step #0 - "super-linter": 2020-09-08 12:04:40 [DEBUG ]     -> Codebase does NOT have file:[./.eslintrc.yml], using Default rules at:[/action/lib/.automation/.eslintrc.yml]
Step #0 - "super-linter": 2020-09-08 12:04:41 [DEBUG ]     -> Codebase does NOT have file:[./.yaml-lint.yml], using Default rules at:[/action/lib/.automation/.yaml-lint.yml]
Step #0 - "super-linter": 2020-09-08 12:04:41 [DEBUG ]   ---------------------------------------------

This is not specific to Hadolint. Files with two dots in their name have this issue. I'm debugging a bit...

@alerque @ruzickap can you check if #696 fixes this issue?

/cc @admiralAwkbar

Hello guys.

I'm sorry to come back so late, but this issue is still in latest super-linter.

See this example:

mkdir /tmp/test
cd /tmp/test

cat > Dockerfile << EOF
FROM alpine
EOF

cat > .hadolint.yaml << EOF
ignored:
  # Always tag the version of an image explicitly
  - DL3006
EOF

Run hadolint which automatically use the .hadolint.yaml config file and doesn't produce any error:

hadolint Dockerfile; echo $?
0

If I run the super-linter it ignores the .hadolint.yaml the hadolint's config file and report error:

docker run -e RUN_LOCAL=true -v ${PWD}:/tmp/lint github/super-linter
...
...
2020-09-16 08:57:23 [INFO  ]   ----------------------------------------------
2020-09-16 08:57:23 [INFO  ]   ----------------------------------------------
2020-09-16 08:57:23 [INFO  ]   Linting [DOCKERFILE_HADOLINT] files...
2020-09-16 08:57:23 [INFO  ]   ----------------------------------------------
2020-09-16 08:57:23 [INFO  ]   ----------------------------------------------
2020-09-16 08:57:23 [INFO  ]   ---------------------------
2020-09-16 08:57:23 [INFO  ]   File:[/tmp/lint/Dockerfile]
2020-09-16 08:57:23 [ERROR ]   Found errors in [hadolint] linter!
2020-09-16 08:57:23 [ERROR ]   [/tmp/lint/Dockerfile:1 DL3006 Always tag the version of an image explicitly]
2020-09-16 08:57:23 [ERROR ]   Linter CMD:[hadolint -c /action/lib/.automation/.hadolint.yml /tmp/lint/Dockerfile]
...
...

Looks to me like super-linter is trying to use .hadolint.yml instead of .hadolint.yaml

Thanks for looking at it...

@ruzickap can you enable debug output with ACTIONS_RUNNER_DEBUG=true and try again? super-linter already checks both yml and yaml, as you will notice by setting ACTIONS_RUNNER_DEBUG to true.

Also, you didn't set LINTER_RULES_PATH, which should point to the directory where you have the .hadolint.yaml file, which is . in this case, if I read your example correctly. So LINTER_RULES_PATH=.

Yeah... LINTER_RULES_PATH=. did the job...

Thank you...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MuhaddiMu picture MuhaddiMu  路  3Comments

kilasuit picture kilasuit  路  5Comments

thehesiod picture thehesiod  路  4Comments

sergey-muntyanu picture sergey-muntyanu  路  4Comments

bbaassssiiee picture bbaassssiiee  路  5Comments