Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings: path to hadolint binary #2

Closed
Frodox opened this issue May 27, 2018 · 7 comments
Closed

Add settings: path to hadolint binary #2

Frodox opened this issue May 27, 2018 · 7 comments

Comments

@Frodox
Copy link

Frodox commented May 27, 2018

Hi!
Thank you for extension!

I'm not pretty clear how vscode-hadolint searchs for system binary in system PATH...
I don't want to install hadolint binary globally. I just create smth like

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

docker run --rm -i hadolint/hadolint 

and put ~/.bin in PATH in my ~/.bashrc.
But vscode doesn't see it. My suggestion --- add settings option --- path to hadolint binary.

@michaellzc
Copy link
Owner

michaellzc commented May 28, 2018

@Frodox

Hi,

Docker container does not have access to the host path, unless you explicitly bind mount host volume into the container. That's why the plugin is not working on your computer and just hang forever without returning anything (If the plugin fails to find hadolint executable from your PATH, it will yell at you with an error notification popover instead).

Current implementation uses /path/to/Dockerfile as the second argument instead of streaming the file through stdin. You can check the code at here.

hadolint /path/to/Dockerfile

hadolint's documentation suggests using stdin when running hadolint from a docker container, https://github.com/hadolint/hadolint#how-to-use

docker run --rm -i hadolint/hadolint < Dockerfile

Therefore, I do not plan to devote my time to support such a special scenario. You are feel free to open a PR with your own implementation tho, as long as it does not break anything.

@Frodox
Copy link
Author

Frodox commented May 28, 2018

Well, this works fine and not a problem:

% 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`

the question more about "how vscode finds my hadolint binary" ? I got an error

Cannot find hadolint from system $PATH. Please install hadolint in advance

so, looks like vscode doesn't load my custom PATH from ~/.bashrc and so on.
So, simple suggestion - just have an extra settings for that.

Because. Hadolint isn't in Linux repos --- fedora, Centos, Debian. There is no deb/rpm packet. And official docs says:

You can download prebuilt binaries for OSX, Windows and Linux from the latest release page.
...
You can also build hadolint locally. You need Haskell and the stack build tool to build the binary.
git clone https://github.com/hadolint/hadolint
cd hadolint
stack install

so, it is completely 'custom' program, which doesn't follow linux-package-way. So, I don't think it is so hard just to check one setting before system call :)

@Frodox
Copy link
Author

Frodox commented May 28, 2018

So, if I start vscode from bash (with custom PATH) it works fine. But it is weird and un-common to start terminal first :)

@michaellzc
Copy link
Owner

michaellzc commented May 29, 2018

@Frodox

Thanks for the feedback!

I didn't know you can workaround with docker run --rm -i hadolint/hadolint < "$@".

I will look into this.

@michaellzc michaellzc reopened this May 29, 2018
@Frodox
Copy link
Author

Frodox commented May 30, 2018

Thanks!

Actually, it is same for any "pre-built" binaries (same as, kubectl, packer, docker-compose and so on) . It is common to put them somewhere in user's custom PATH, like ~/.bin, not in system binary system-wide

michaellzc added a commit that referenced this issue May 30, 2018
You can now set full path to hadolint executable either by editting settings.json or using the
vscode command

#2
michaellzc added a commit that referenced this issue May 30, 2018
You can now set full path to hadolint executable either by editting settings.json or using the
vscode command

#2
@michaellzc
Copy link
Owner

@Frodox

You can set the full path to hadolint executable by

  • Type Hadolint: Select Hadolint Executable in the Command Palette. A list of hadolint executables exist in your $PATH will show up and you can select any one of them.

or somehow the executable is not showing up (which I have not run into before)

  • Edit the hadolint.hadolintPath in user settings.

@michaellzc
Copy link
Owner

FYI, #44 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants