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

Can skaffold debug support npm run-scripts #2044

Closed
briandealwis opened this issue Apr 30, 2019 · 4 comments · Fixed by #2141
Closed

Can skaffold debug support npm run-scripts #2044

briandealwis opened this issue Apr 30, 2019 · 4 comments · Fixed by #2141

Comments

@briandealwis
Copy link
Member

skaffold debug supports configuring NodeJS applications for debugging providing their the container entrypoint or command is node or nodemon. But some apps, like our own examples/nodejs use npm run xxx to run a script: (

CMD ["npm", "run", "dev"]

which itself executes nodemon:
"dev": "nodemon index.js"

Perhaps skaffold debug for NodeJS should parse and retrieve the script line.

@briandealwis
Copy link
Member Author

The npm run docs say that:

  • npm run xxx looks up the xxx script in the package.json
  • any arguments after a --` is passed appended to the script
  • it adds node_modules/.bin to the PATH
  • the shell used can be customized with the shell-script configuration
  • executed from the root of the module

So trying to emulate npm runto synthesize a command-line, so as to be able to apply the same transformation that skaffold debug has been doing with node and nodemon, would require that we extract the package.json from the image. Which doesn't seem easy nor ideal.

An alternative is that node >= 8 supports a NODE_OPTIONS environment variable. It can be overridden by a node-options in the package.json

@briandealwis
Copy link
Member Author

So it turns out we cannot use NODE_OPTIONS as it's picked up by npm's node as well as the underlying app's node too.

DEBU[0022] Running command: [kubectl logs --since=19s -f npm -c web --namespace default] 
[npm web] Debugger listening on ws://127.0.0.1:9229/fca610da-37a2-46dd-9b94-29982966f47c
[npm web] For help see https://nodejs.org/en/docs/inspector
[npm web] 
[npm web] > backend@1.0.0 dev /opt/backend
[npm web] > nodemon src/index.js
[npm web] 
[npm web] Starting inspector on 127.0.0.1:9229 failed: address already in use

@briandealwis
Copy link
Member Author

We can use npm run xxx --node-options=--inspect=nnn, but it suffers from the same problem if the npm script uses nodemon since the inspect is first take up by nodemon's node. Sadly our examples/nodejs does this :-(

"scripts": {
"dev": "nodemon src/index.js"
},

@briandealwis
Copy link
Member Author

Follow-up in #2170.

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

Successfully merging a pull request may close this issue.

3 participants