vscode-docker icon indicating copy to clipboard operation
vscode-docker copied to clipboard

Linting issues with ${env:variable} syntax in Dockerfile ENTRYPOINT and CMD statements

Open DJFormica opened this issue 5 years ago • 4 comments

Issue 952 describes a scenario where the Powershell curly brace string syntax, ${env:variable} is evaulated as an invalid syntax in a RUN statement, generating the following error:

failed to process "${env:variable}": unsupported modifier (v) in substitutiondockerfile-utils(44)

Issue 952 was resolved for RUN statements (and most other statements, it appears). However, the issue still exists for ENTRYPOINT and CMD statements. Consider the following two examples:

ENTRYPOINT powershell -Command `
  kubectl port-forward --address ${env:address} pod/${env:podname} ${env:source}:${env:dest} -n ${env:namespace}

CMD powershell -Command `
  kubectl port-forward --address ${env:address} pod/${env:podname} ${env:source}:${env:dest} -n ${env:namespace}

In both cases, the linting error will be displayed in vscode and the file will appear in red in the file pane, indicating that there is an unresolved syntax error in the file. Putting the same command in front of a RUN statement does not produce the error (as it was fixed in Issue 952). Additionally, this is specific to the curly brace syntax; if the string variable is rendered as $env:variable it is correctly parsed and ignored. Finally, as cited in Issue 952 and related issues and discussions, the error is a red herring and the Dockerfile builds without issues.

After examining the pull request and fix for Issue 952, it appears the actual fix was implemented in the dockerfile language server project which is written and maintained by @rcjsuen. Based on the test criteria for the fix (a dockerfile with a list of statements and corresponding values with colons in-line) I am guessing that ENTRYPOINT and CMD need to be added to the list of statements which exclude this syntax check (RUN, ENV, ARG, etc). However, I can't find where in the dockerfile-language-server-nodejs code this actually happens; so far, all I can find is a reference to issue #56 where it was cited in the readme. Otherwise I would try to fix it myself and submit a PR.

On that note, if you do choose to resolve this issue, can you please cite the code in the language server project which is changed so that I may study it? I feel a bit dull that I'm unable to locate it, so it would be helpful to understand where it was and why I could not find it using the PRs and issues as guidance.

This issue is present in the most recent stable release of vscode for Windows:

Version: 1.53.2 (system setup)
Commit: 622cb03f7e070a9670c94bae1a45d78d7181fbd4
Date: 2021-02-11T11:48:04.245Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.18362
ms-azuretools.vscode-docker: 1.10.0

DJFormica avatar Feb 26 '21 22:02 DJFormica

@DJFormica Thank you for your bug report. This has now been fixed in https://github.com/rcjsuen/dockerfile-utils/issues/89. And that also answers your other question in a way, which is that the Dockerfile validation code is in the rcjsuen/dockerfile-utils repository.

rcjsuen avatar Feb 27 '21 12:02 rcjsuen

Thank you! I appreciate it :-)

DJFormica avatar Mar 01 '21 15:03 DJFormica

@DJFormica This should get fixed with #2866.

rcjsuen avatar Apr 11 '21 16:04 rcjsuen

Reopening this for tracking in 1.13.0

bwateratmsft avatar Apr 12 '21 13:04 bwateratmsft