-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix #1463. Allow to expose multiple ports when running in debug mode #1479
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56f4802
Fix #1463. Allow to expose multiple ports when running in debug mode
sdubov 030b5ae
Add multiple=true flag for --debug-port option
sdubov 249ccec
Update documentation for DebugContext to reflect latest changes
sdubov a2b9b05
Fix DebugContext debug_port parameter name and documentation
sdubov c4d52e2
Merge branch 'develop' into sdubov-multi-debug-ports
sdubov 5560d22
Re-format code with Black
sdubov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| Title: Template for design documents | ||
| ==================================== | ||
|
|
||
| What is the problem? | ||
| -------------------- | ||
| Currently, there is one port is exposed from Docker instance when running lambda in debug mode. | ||
| This port is used to connect a debugger. In my case, I need two ports to be exposed due to Debugger | ||
| implementation specific (the Debugger connect to two sockets to collect different information). | ||
|
|
||
| What will be changed? | ||
| --------------------- | ||
| SAM CLI has a ``--debug-port`` parameter that provide a port. This parameter is stored in DebugContext object. | ||
| ``DebugContext`` should store an array of ports instead of a single port. This array should be transformed | ||
| into a map containing each stored port when passing to docker container arguments. | ||
|
|
||
| Success criteria for the change | ||
| ------------------------------- | ||
| All ports specified via single or multiple ``--debug-port`` SAM CLI options should be exposed by docker container. | ||
|
|
||
| Out-of-Scope | ||
| ------------ | ||
|
|
||
| User Experience Walkthrough | ||
| --------------------------- | ||
| From the user perspective, it should only provide an ability to specify multiple ``--debug-port`` options: | ||
| ``--debug-port 5600 --debug-port 5601`` | ||
|
|
||
| Implementation | ||
| ============== | ||
|
|
||
| CLI Changes | ||
| ----------- | ||
|
|
||
| SAM CLI provide an option to specify multiple ports ``--debug-port 5600 --debug-port 5601``. | ||
|
|
||
| ### Breaking Change | ||
|
|
||
| No changes. | ||
|
|
||
| Design | ||
| ------ | ||
|
|
||
| Update ``--debug-port`` option to allow to use it multiple times in SAM CLI. | ||
| The option type should take only integer values. The value is stored in ``DebugContext``. | ||
| This value should be converted into a map of ``{ container_port : host_port }`` | ||
| that is passed to ``ports`` argument when creating a docker container. | ||
|
|
||
| `.samrc` Changes | ||
| ---------------- | ||
|
|
||
| No changes. | ||
|
|
||
| Security | ||
| -------- | ||
|
|
||
| No changes. | ||
|
|
||
| **What new dependencies (libraries/cli) does this change require?** | ||
|
|
||
| **What other Docker container images are you using?** | ||
|
|
||
| **Are you creating a new HTTP endpoint? If so explain how it will be | ||
| created & used** | ||
|
|
||
| **Are you connecting to a remote API? If so explain how is this | ||
| connection secured** | ||
|
|
||
| **Are you reading/writing to a temporary folder? If so, what is this | ||
| used for and when do you clean up?** | ||
|
|
||
| **How do you validate new .samrc configuration?** | ||
|
|
||
| What is your Testing Plan (QA)? | ||
| =============================== | ||
|
|
||
| Goal | ||
| ---- | ||
| Make sure SAM CLI users can specify multiple ports and those ports are exposed | ||
| after creating a docker container in debug mode: | ||
|
|
||
| ``sam local invoke --template <path_to_template>/template.yaml --event <path_to_event>/event.json --debugger-path <path_to_debugger> --debug-port 5600 --debug-port 5601`` | ||
|
|
||
| Pre-requesites | ||
| -------------- | ||
| Running SAM CLI with debug mode. | ||
|
|
||
| Test Scenarios/Cases | ||
| -------------------- | ||
| 1. Single port is specified: ``--debug-port 5600`` | ||
| 2. Multiple ports are specified: ``--debug-port 5600 --debug-port 5601`` | ||
| 3. No ports specified: ``--debug-port `` | ||
| 4. No ``--debug-port`` parameter is specified | ||
|
|
||
| Expected Results | ||
| ---------------- | ||
| 1. Single port is exposed in docker container | ||
| 2. All specified ports are exposed in docker container | ||
| 3. No ports exposed. | ||
| 4. No ports exposed. | ||
|
|
||
| Pass/Fail | ||
| --------- | ||
|
|
||
| Documentation Changes | ||
| ===================== | ||
|
|
||
| Open Issues | ||
| ============ | ||
| - [1463](https://github.com/awslabs/aws-sam-cli/issues/1463) | ||
|
|
||
| Task Breakdown | ||
| ============== | ||
|
|
||
| - \[x\] Send a Pull Request with this design document | ||
| - \[ \] Build the command line interface | ||
| - \[ \] Build the underlying library | ||
| - \[x\] Unit tests | ||
| - \[x\] Functional Tests | ||
| - \[x\] Integration tests | ||
| - \[ \] Run all tests on Windows | ||
| - \[x\] Update documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,20 +92,25 @@ def __init__( | |
| @staticmethod | ||
| def _get_exposed_ports(debug_options): | ||
| """ | ||
| Return Docker container port binding information. If a debug port is given, then we will ask Docker to | ||
| bind to same port both inside and outside the container ie. Runtime process is started in debug mode with | ||
| Return Docker container port binding information. If a debug port tuple is given, then we will ask Docker to | ||
| bind every given port to same port both inside and outside the container ie. Runtime process is started in debug mode with | ||
| at given port inside the container and exposed to the host machine at the same port | ||
|
|
||
| :param int debug_port: Optional, integer value of debug port | ||
| :param DebugContext debug_options: Debugging options for the function (includes debug port, args, and path) | ||
| :return dict: Dictionary containing port binding information. None, if debug_port was not given | ||
| """ | ||
| if not debug_options: | ||
| return None | ||
|
|
||
| return { | ||
| # container port : host port | ||
| debug_options.debug_port: debug_options.debug_port | ||
| } | ||
| if not debug_options.debug_ports: | ||
| return None | ||
|
|
||
| # container port : host port | ||
| ports_map = {} | ||
| for port in debug_options.debug_ports: | ||
| ports_map[port] = port | ||
|
|
||
| return ports_map | ||
|
|
||
| @staticmethod | ||
| def _get_additional_options(runtime, debug_options): | ||
|
|
@@ -169,17 +174,20 @@ def _get_entry_point(runtime, debug_options=None): # pylint: disable=too-many-b | |
| Dockerfile. We override this default specifically when enabling debugging. The overridden entry point includes | ||
| a few extra flags to start the runtime in debug mode. | ||
|
|
||
| :param string runtime: Lambda function runtime name | ||
| :param int debug_port: Optional, port for debugger | ||
| :param string debug_args: Optional additional arguments passed to the entry point. | ||
| :param string runtime: Lambda function runtime name. | ||
| :param DebugContext debug_options: Optional. Debug context for the function (includes port, args, and path). | ||
| :return list: List containing the new entry points. Each element in the list is one portion of the command. | ||
| ie. if command is ``node index.js arg1 arg2``, then this list will be ["node", "index.js", "arg1", "arg2"] | ||
| """ | ||
|
|
||
| if not debug_options: | ||
| return None | ||
|
|
||
| debug_port = debug_options.debug_port | ||
| debug_ports = debug_options.debug_ports | ||
| if not debug_ports: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is fine but I think it is not needed. |
||
| return None | ||
|
|
||
| debug_port = debug_ports[0] | ||
| debug_args_list = [] | ||
|
|
||
| if debug_options.debug_args: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
-dis passed as a string, would this cause any issues? I understand why you would add this but not sure if this affects if the integer was pass as a string ("33333" for example). I want to make sure we don't accidentally break the existing contract here.I didn't find any specific information on click, but will the
debug-portalways be a list when passed to ourclimethods? I am having a hard time understanding how type in impacts what click will end up passing us.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues with passing integer as a string here. Looked to the
clickparameters type processing logic - it tries to cast a value to integer. Verified it works well with strings unless you specify an invalid value, e.g. "abc" that sounds like an expected behavior.Looked through
clickimplementation for handlingmultipleflag - it wraps values intotupleif flag is set and return them or return an empty tuple if no values. So, I would expect we always havetupleafter processing--debug-portoption. Verified with single and multiple values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. Thanks for digging into that.