cookiecutter / cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.
https://cookiecutter-django.readthedocs.io
BSD 3-Clause "New" or "Revised" License
11.98k stars 2.88k forks source link

Add Hadolint #4768

Open Andrew-Chen-Wang opened 8 months ago

Andrew-Chen-Wang commented 8 months ago

Description

Adding hadolint to pre-commit

Rationale

Linting Dockerfile. Current lint warnings:

Lint Dockerfiles.........................................................Failed
- hook id: hadolint-docker
- exit code: 1

compose/local/django/Dockerfile:10 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/local/django/Dockerfile:17 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
compose/local/django/Dockerfile:38 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/local/django/Dockerfile:38 DL3009 info: Delete the apt-get lists after installing something
compose/local/django/Dockerfile:49 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/local/django/Dockerfile:68 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/local/django/Dockerfile:72 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/local/django/Dockerfile:77 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/local/django/Dockerfile:81 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/local/django/Dockerfile:85 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/local/docs/Dockerfile:10 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/local/docs/Dockerfile:35 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/local/docs/Dockerfile:55 DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
compose/local/docs/Dockerfile:60 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/production/django/Dockerfile:11 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/production/django/Dockerfile:18 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
compose/production/django/Dockerfile:42 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
compose/production/django/Dockerfile:62 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/production/django/Dockerfile:67 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/production/django/Dockerfile:70 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/production/django/Dockerfile:75 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
compose/production/django/Dockerfile:80 DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
shywn-mrk commented 3 months ago

I can work on this, is this still relevant? The problem is that still pre-commit throws some errors on some files that need to be fixed or in some cases ignored. However they could be solved in a different issue. I can work on this also fix them so that the pre-commit comes clean right of the box.

Andrew-Chen-Wang commented 3 months ago

Feel free to use this pre-commit as a starting point:

  - repo: https://github.com/hadolint/hadolint
    rev: v2.12.0
    hooks:
      - id: hadolint
        exclude: ^.*\.jinja2$

It does seem like it's not maintained; finding an alternative may be beneficial.