hadolint / hadolint-action

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

How to lint multiple dockerfiles, without specifying the action for each? #54

Closed mfn closed 2 years ago

mfn commented 2 years ago

With the version on the terminal, I can run it like so and get multiple files linted:

+ $ hadolint Dockerfile*
Dockerfile-test1:9 DL3003 warning: Use WORKDIR to switch to a directory
Dockerfile-test2:21 DL3003 warning: Use WORKDIR to switch to a directory

But with the action, I can't get it working:

      - uses: hadolint/hadolint-action@v2.0.0
        with:
          dockerfile: Dockerfile*

produces

hadolint: Dockerfile*: openBinaryFile: does not exist (No such file or directory)

It acts like I would use single quotes in bash to prevent wildcard expansion:

+ $ hadolint 'Dockerfile*'
hadolint: Dockerfile*: openBinaryFile: does not exist (No such file or directory)
kgrv-me commented 2 years ago

Hope I'm not too late to help out.

ISSUE #3 contains a lot of conversation regarding this topic. You have several options:

  1. Using 3rd-party GitHub Action (https://github.com/hadolint/hadolint-action/issues/3#issuecomment-825619183)
  2. Apparently, setting HADOLINT_RECURSIVE environment variable to true seems to work somewhat (https://github.com/hadolint/hadolint-action/issues/3#issuecomment-1078208689)
  3. If you don't mind using Docker container, I built one (so it's CI platform agnostic) kgrv/hadolint It can scan entire directories (including nested) with simple docker run command
    docker run --rm -v PATH:/workspace kgrv/hadolint

    Integrate this into GitHub workflow with:

    - name: Haskell Dockerfile Linter
    run: docker run --rm -v ${PWD}:/workspace kgrv/hadolint

I hope this helps, cheers!

mfn commented 2 years ago

Ah,thanks! Totally forgot about this one.

I made a super-weird workaround:

name: Lint Docker files
on:
  push:
    paths:
      - .github/workflows/docker_lint.yaml
      - .hadolint.yaml
      - Dockerfile*
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Install hadolint
        run: |
          docker pull hadolint/hadolint:latest
          container_id=$(docker create hadolint/hadolint)
          docker cp $container_id:/bin/hadolint .

      - run: ./hadolint --version

      - run: ./hadolint Dockerfile*

Given what you wrote, it feels most natural to just go with https://github.com/jbergstroem/hadolint-gh-action to me, will check it out.

Since I could work it around already and more options are on the table and no one seems to work on the issues reporting here anyway -> closing!

Thanks 🙏🏼