hadolint / hadolint-action

GitHub action for Hadolint, A Dockerfile linting tool
MIT License
192 stars 50 forks source link

[INVESTIGATED/TESTED] Configuration File Pathing Issue + Subsequent Issue #58

Open kgrv-me opened 2 years ago

kgrv-me commented 2 years ago

Please refer to PR #59 for detailed solutions.

ISSUES

TEST CASES

- uses: hadolint/hadolint-action@v2.1.0
  with:
    config: PATH

Substitute PATH with the followings:

hadolint.yaml
./hadolint.yaml
.hadolint.yaml
/home/runner/work/sandbox/sandbox/hadolint.yaml

INVESTIGATION

  1. hadolint looks for configuration files via
    $PWD/.hadolint.yaml
    $XDG_CONFIG_HOME/hadolint.yaml
    $HOME/.config/hadolint.yaml
    $HOME/.hadolint/hadolint.yaml or $HOME/hadolint/config.yaml
    $HOME/.hadolint.yaml

NOTE hadolint-action utilizes Docker container for execution

  1. hadolint uses PWD and HOME environment variables
  2. action.yml maps inputs.config to HADOLINT_CONFIG
  3. Dockerfile points to hadolint.sh for entrypoint
  4. hadolint.sh appends -c ${HADOLINT_CONFIG} to hadolint command
  5. hadolint-action uses Docker with
docker run .. --workdir /github/workspace .. -v "/home/runner/work/sandbox/sandbox":"/github/workspace" ..
  1. PWD=/ and HOME=/root inside the container

CONCLUSION

  1. Since pwd inside the container isn't matching with PWD nor HOME, hadolint cannot find configuration file in usual places
  2. Knowing pwd and -v for the container, we can edit PATH to be /github/workspace/hadolint.yaml for hadolint-action to use

SUGGESTION

Thank you!

lorenzo commented 2 years ago

Would you like to submit a change with those fixes?

kgrv-me commented 2 years ago

@lorenzo I could definitely do that! ~How would I proceed to do so?~ EDIT: I have opened PR #59 for the solutions :D