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

Not working when using SSH remote #35

Closed OiYouYeahYou closed 4 years ago

OiYouYeahYou commented 4 years ago

I am using the VSC Remote Development extension to develop in a VM. I have built and installed hadolint on that VM. The binary is here /home/jason/.local/bin/hadolint and is on the path.

But the extension is unable to find the binary

Error:

{ Error: spawnSync hadolint ENOENT
    at Object.spawnSync (internal/child_process.js:982:20)
    at Object.spawnSync (child_process.js:596:24)
    at Function.spawnSync [as sync] (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/cross-spawn/index.js:26:23)
    at Object.lint (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/service/hadolint.js:30:35)
    at validateTextDocument (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/server.js:47:49)
    at documents.onDidOpen (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/server.js:22:5)
    at CallbackList.invoke (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/events.js:62:39)
    at Emitter.fire (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/events.js:120:36)
    at connection.onDidOpenTextDocument (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-languageserver/lib/main.js:180:29)
    at handleNotification (/home/jason/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/main.js:489:43)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawnSync hadolint',
  path: 'hadolint',
  spawnargs: [ '/home/jason/Dockerfile' ] }

I had suspected that the extension is looking for the binary on my client instead of host. But the extension is running in the VM so I'm puzzled. The folloing is the error on a clean test user on the same VM to at least prove that the extesnion is on the VM not client

Error:

{ Error: spawnSync hadolint ENOENT
    at Object.spawnSync (internal/child_process.js:982:20)
    at Object.spawnSync (child_process.js:596:24)
    at Function.spawnSync [as sync] (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/cross-spawn/index.js:26:23)
    at Object.lint (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/service/hadolint.js:30:35)
    at validateTextDocument (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/server.js:47:49)
    at documents.onDidSave (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/out/server.js:26:5)
    at CallbackList.invoke (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/events.js:62:39)
    at Emitter.fire (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/events.js:120:36)
    at connection.onDidSaveTextDocument (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-languageserver/lib/main.js:223:33)
    at handleNotification (/home/test/.vscode-server/extensions/exiasr.hadolint-0.3.0/server/node_modules/vscode-jsonrpc/lib/main.js:489:43)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawnSync hadolint',
  path: 'hadolint',
  spawnargs: [ '/home/test/Dockerfile' ] }
michaellzc commented 4 years ago

Hi @OiYouYeahYou ,

Thanks for reaching out.

Actually I didn't try out the remote dev feature till last week :(

I will properly take a look into this later this month.

OiYouYeahYou commented 4 years ago

Thank you for the reply, I hope it's an easy bug to fix :smile:

michaellzc commented 4 years ago

Hi @OiYouYeahYou ,

I have identified the root cause of the issue.

It looks like the config, hadolint.hadolintPath (the configuration of the path to the executable) on the vscode-server (the instance of vscode running on your remote host, container, etc) is inherent from the global setting of the local machine which initiates the setup.

Therefore, if you have prior custom path config on the local machine, this could break the extension on the remote host (unlike the default setting, it's just hadolint instead of an absolute path to the executable).

I would suggest creating a workspace settings on the remote host with hadolint.hadolintPath set to either hadolint or the absolute path to the executable in case the former is not available in the $PATH

{remote_project_root}/.vscode/settings.json

{
  "hadolint.hadolintPath": "/home/ubuntu/.bin/hadolint"
}

In terms of the fix, unless vscode supports namespace for extension configuration, i.e, config.local.hadolint, config.remote.hadolint, I am not sure what is the proper way to handle such a scenario.

SuperSandro2000 commented 4 years ago

Can I point it to $HOME/.local/bin/hadolint?

michaellzc commented 4 years ago

Of course, that’s just any example.

On Dec 24, 2019, at 7:05 AM, Sandro notifications@github.com wrote:



Can I point it to $HOME/.local/bin/hadolint?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FExiaSR%2Fvscode-hadolint%2Fissues%2F35%3Femail_source%3Dnotifications%26email_token%3DAB74GDDONFGHLSOZUSN2HZTQ2IJLXA5CNFSM4JPUMNXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHTICMI%23issuecomment-568754481&data=02%7C01%7C%7C476fdbd342564dddca1108d7887a609b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637127931487641642&sdata=tW78pkVe7faykoEsoErVqBAgeuXijzOGZagQdh5TUrg%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAB74GDCYOH46K3AQ7G5MKPLQ2IJLXANCNFSM4JPUMNXA&data=02%7C01%7C%7C476fdbd342564dddca1108d7887a609b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637127931487641642&sdata=pMFNRA3yBDOnx4zQXJNk12SDq%2FnxfiHV%2FcsZL9oy%2FHE%3D&reserved=0.