Debug in Docker
barfet opened this issue · 6 comments
Hello,
Thank you for all your efforts!
I have a question regarding debugging sls offline that is run inside of Docker container. And as an edge case, behind Nginx proxy.
In docs you have section for debugging, but it only covers local debug with node-inspector and Chrome. What is the suggested way on how to debug inside of Docker container?
Thanks a lot!
I found the way how to debug sls offline
with .map files in Docker:
- EXPOSE 8080 port from container (default port for debug)
- Run
node-debug --web-host 0.0.0.0 serverless offline start
. We could use--web-host
for remote debugging. - Add
node-inspector
topackage.json
Next will be steps for debugging with .map files
-
Add
"sourceMap": true
tocompilerOptions
intsconfig.json
-
Add
devtool: 'inline-source-map',
tomodule.exports
in webpack base config. -
Run Docker and navigate to http://127.0.0.1:8080/?port=5858 to set breakpoints
Maybe it's not 100% related to the serverless-offline
plugin, but I want to achieve fully interacting development environment for developing Lambda functions. Currently I was able to setup remote debugging and it's working fine, but now I'm thinking on how to add responsiveness to this development process.
I mean that when you add some changes to the code (I will be talking about my use case with Webpack, Typescript and serverless-webpack) we could rebuild typescript with sls webpack
and our app.js
file will be updated and served with new changes. And here comes two questions:
- How to reattach
node-inspector
and reload it's UI to correspond this changes? - What is the proper way to recompile
.ts
file withsls webpack
. I tried to achieve this withnodemon
that will watch for changes insrc
folder, but was unsuccessful with this.
If anyone was able to achieve this desired functionally, I would be very appreciated for knowledge sharing! And it will be nice to have all info in one place, for future.
We have a great communication with @HyperBrain in sls webpack
repo regarding debugging of serverless in Docker containers. You could reference this topic for the further info:
serverless-heaven/serverless-webpack#215
It seems like the main problem with Debugging in Docker is in type of file watch that Webpack is using.
I added polling support to serverless-webpack
now. It will be part of the next version. Everyone interested can check if the PR works as expected (serverless-heaven/serverless-webpack#225).
Hi @barfet ! I am currently experiencing the error
events.js:183
throw er; // Unhandled 'error' event
^
Error: spawn java ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
while I run a node:6.10 Docker container with serverless offline and dynamodb local on it.
Would it be possible for you to share your Dockefile to see if it works in my case? It seems that error is currently a common problem
Many thanks in advance
Sorry for the late response, I just saw that there is Notifications on GitHub:)
You could check my repo with serverless-typescript-starter.
https://github.com/barfet/serverless-typescript-starter
It includes debugging in VS Code, recompilation on file changes and re-run unit tests.