Closed briandealwis closed 4 years ago
I think it's hard to understand what you mean in the description. Can you include like a before and after transformation (or something in the description)?
Rewrote description and made some other fixes.
PTAL @dgageot
This PR:
--inspect
-style arguments are only used when running application scripts.nodejs
debug helper image that installs thisnode
wrapper.Towards fixing GoogleContainerTools/skaffold#2170. With this
nodejs
debug helper image in place, we can then changeskaffold debug
to 1) use the debug helper image, and 2) set PATH to cause this node-wrapper to be invoked.NodeJS's
node
supports a set of--inspect
arguments to activate debugging mode using the Chrome DevTools protocol. There are a few variants:--inspect
or--inspect=<port>
: launches the app with devtools listening on the given port (or default 9229)--inspect-brk
or--inspect-brk=<port>
: launches but immediately stops the appMany NodeJS applications use NodeJS-based tools like
npm
andnodemon
to launch the app rather than runningnode
directly, and often use several layered together. For example, Skaffold's ownnodejs
example uses npm invoking nodemon, which then invokes node. Further complicating the issue is that thenode
images on Docker Hub usedocker-entrypoint.sh
as a helper script for launching apps. So this example might cause the following sequence:docker-entrypoint.sh sh -c 'npm run production'
npm run production
node /path/to/npm run production
node src/index.js
This sequence makes it very difficult for
skaffold debug
to start launch the application for debugging as--inspect
s are usually intercepted by one of the launch tools.This PR provides a node wrapper that adds special handling for
--inspect
-style arguments on the command-line andNODE_OPTIONS
environment variable. When executing anode_modules
script, any--inspect
-like arguments are stripped and put inNODE_DEBUG
. When executing an application script (i.e., does not live innode_modules
), theNODE_DEBUG
value is inlined.For example,
skaffold debug -p dev
onnodejs
example would do the following:docker-entrypoint.sh sh -c 'npm run production'
withNODE_OPTIONS=--inspect=9229
but withPATH=/path/to/this/wrapper:$PATH
npm run production
(withNODE_OPTIONS=--inspect=9229
)/path/to/this/wrapper/node /path/to/npm run production
—npm
is recognized as a non-application script and thus the--inspect=9229
is stripped from theNODE_OPTIONS
and placed it inNODE_DEBUG
/path/to/actual/node /path/to/npm run production
/path/to/this/wrapper/node src/index.js
—src/index.js
is recognized as an application script and soNODE_DEBUG
is inlined to thenode
command-line/path/to/actual/node --inspect=9229 src/index.js
If you have npm/node on your system, you can check it out with something as simple as:
Whereas with the node-wrapper in place:
To see it in action, we use Skaffold's simple NodeJS project with
npm
and thenode
image: