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

MICRO-50: Support step through debug with VSCode #549

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kai-nguyen-aligent
Copy link
Contributor

This PR aims to add the ability to debug lambda function with VSCode. There are couple of notes as listed below:

  • This approach leverage the VSCode Docker extension to build and run our aligent/serverless:debug docker container for debugging purpose.
  • Enable sourcemap and disable minify through environment variable when building with esbuild to support debugging by invoke local.
  • There is a caveat while using invoke local to debug. After a code change, the first time we try to debug with invoke local, VSCode will fail to attach to the debugger. This happens because serverless will not build our code until we trigger that invocation. All the sub sequence launches will success and we will be able to attach to the debugger normally.

@kai-nguyen-aligent
Copy link
Contributor Author

@tvhees I'm looking into supporting the same functionality for PHPStorm but probably will be another PR.

Copy link
Contributor

@TheOrangePuff TheOrangePuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments / questions

Dockerfile Outdated Show resolved Hide resolved
@@ -4,6 +4,8 @@
"description": "Serverless ESBuild example using Typescript",
"main": "handler.js",
"scripts": {
"debug-test": "node --inspect=0.0.0.0 ./node_modules/.bin/jest --runInBand",
"debug-invoke-local": "MINIFY=false SOURCEMAP=true node --inspect=0.0.0.0 ./node_modules/.bin/serverless invoke local",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can ./node_modules/.bin/serverless be changed to use the serverless docker image? We want to avoid confusion for developers where something might work when they run the serverless command but doesn't work when they run serverless from node_modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheOrangePuff : Yes, we can do that. However, I'm not sure if we should do it though. The problem here is that anytime you run serverless command from inside your project, node will use the locally installed package instead of the global one as shown below:

$ cat ~/.aligent_aliases 
alias node-run='docker run --rm -it -v ~/.aws:/home/node/.aws -v ~/.azure:/home/node/.azure -v ~/.npm:/home/node/.npm -v "$PWD:/app" aligent/serverless:latest'
alias serverless='node-run serverless'                                                                                                                                                                                                                                                                                                                                       
$ serverless --version
Framework Core: 3.22.0
Plugin: 6.2.2
SDK: 4.3.2

$ cd ./serverless-aws-nodejs-service-template
$ rm -rf node_modules  
$ node-run npm ci      
$ serverless --version
Running "serverless" from node_modules
Framework Core: 3.18.2 (local) 3.22.0 (global)
Plugin: 6.2.2
SDK: 4.3.2

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

Successfully merging this pull request may close these issues.

2 participants