michaellzc / vscode-hadolint

VSCode extension to integrate hadolint, a Dockerfile linter, into VSCode
https://marketplace.visualstudio.com/items?itemName=exiasr.hadolint
MIT License
77 stars 5 forks source link

Add support for running hadolint from docker image #37

Closed RossBarnie closed 4 years ago

RossBarnie commented 4 years ago

Feature Request

Happy to help with implementation/testing if feature accepted.

Summary

Currently we must select an executable to run hadolint however I do not want to have to build and then maintain my local hadolint executable so I'd like to specify the VSCode extension to always run hadolint from its docker image, like so docker run --rm -i $IMAGE < $FILE_TO_LINT where IMAGE is the specified image in the config variable, and FILE_TO_LINT is the dockerfile to be linted.

Additional Configuration Variables

Run from docker image - A checkbox with a note along the lines of "This overrides the executable path variable. Runs hadolint from the hadolint/hadolint docker image". Unchecked by default, extension runs as normal using the executable. When checked, uses the docker image specified and runs as a container.

hadolint docker image - the name and tag of the image, eg the default would be hadolint/hadolint:latest

michaellzc commented 4 years ago

I would prefer not to introduce extra complexity to the extension unless necessary.

You can use the bash script below to create your ownhadolint executable.

$ cat ~/.bin/hadolint                                   ~
#!/bin/bash

docker run --rm -i hadolint/hadolint < "$@"
---
$ hadolint Dockerfile                                        ⏎
/dev/stdin:3 DL3008 Pin versions in apt get install. Instead of `apt-get in
stall <package>` use `apt-get install <package>=<version>`
/dev/stdin:3 DL3009 Delete the apt-get lists after installing something
/dev/stdin:3 DL3015 Avoid additional packages by specifying `--no-install-r
ecommends`

If the file does not exist under $PATH, you can use the custom hadolint.hadolintPath to set the path.

Credits: https://github.com/ExiaSR/vscode-hadolint/issues/2

michaellzc commented 3 years ago

FYI https://github.com/ExiaSR/vscode-hadolint/issues/44#issuecomment-808756114

0uep commented 2 years ago

As this extension may add some Hadolint options (see setting hadolint.cliOptions set to --no-color by default), I am using the following workaround wrapper script based on Podman:

#!/bin/bash
dockerfile="$1"
shift
podman run --rm -i docker.io/hadolint/hadolint hadolint "$@" - < "$dockerfile"