Skip to content

Commit

Permalink
Revert "feat(debugging): Support debugging Golang functions. (#495)" (#…
Browse files Browse the repository at this point in the history
…526)

This reverts commit 9ae4b80.
The commit breaks functional and integ tests. Reverting to make develop buildable
  • Loading branch information
jfuss authored Jul 3, 2018
1 parent 4e38405 commit 026a747
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 278 deletions.
41 changes: 0 additions & 41 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,47 +395,6 @@ port to your host machine.
issue <https://github.com/Microsoft/vscode-python/issues/71>`__ for
updates.

Debugging Golang functions
^^^^^^^^^^^^^^^^^^^^^^^^^^

Golang function debugging is slightly different when compared to Node.JS,
Java, and Python. We require `delve <https://github.com/derekparker/delve>`__
as the debugger, and wrap your function with it at runtime. The debugger
is run in headless mode, listening on the debug port.

You must compile `delve` to run in the container and provide its local path
via the `--debugger-path` argument. Build delve locally as follows:

`GOARCH=amd64 GOOS=linux go build -o <output path> github.com/derekparker/delve/cmd/dlv`

Then invoke `sam` similar to the following:

`sam local start-api -d 5986 --debugger-path <output path>`

The following is an example launch configuration for Visual Studio Code to
attach to a debug session.

.. code:: bash
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to Lambda container",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "",
"port": <debug port>,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
},
]
}
Passing Additional Runtime Debug Arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
11 changes: 7 additions & 4 deletions samcli/commands/local/cli_common/invoke_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ def __init__(self,
template_file,
function_identifier=None,
env_vars_file=None,
debug_port=None,
debug_args=None,
docker_volume_basedir=None,
docker_network=None,
log_file=None,
skip_pull_image=None,
aws_profile=None,
debug_context=None):
aws_profile=None):
"""
Initialize the context
Expand All @@ -62,12 +63,13 @@ def __init__(self,
self._template_file = template_file
self._function_identifier = function_identifier
self._env_vars_file = env_vars_file
self._debug_port = debug_port
self._debug_args = debug_args
self._docker_volume_basedir = docker_volume_basedir
self._docker_network = docker_network
self._log_file = log_file
self._skip_pull_image = skip_pull_image
self._aws_profile = aws_profile
self._debug_context = debug_context

self._template_dict = None
self._function_provider = None
Expand Down Expand Up @@ -144,7 +146,8 @@ def local_lambda_runner(self):
function_provider=self._function_provider,
cwd=self.get_cwd(),
env_vars_values=self._env_vars_value,
debug_context=self._debug_context,
debug_port=self._debug_port,
debug_args=self._debug_args,
aws_profile=self._aws_profile)

@property
Expand Down
3 changes: 0 additions & 3 deletions samcli/commands/local/cli_common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ def invoke_common_options(f):
"port on localhost.",
envvar="SAM_DEBUG_PORT"),

click.option('--debugger-path',
help="Host path to a debugger that will be mounted into the Lambda container."),

click.option('--debug-args',
help="Additional arguments to be passed to the debugger",
envvar="DEBUGGER_ARGS"),
Expand Down
33 changes: 10 additions & 23 deletions samcli/commands/local/invoke/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from samcli.commands.local.cli_common.options import invoke_common_options
from samcli.commands.local.cli_common.user_exceptions import UserException
from samcli.commands.local.cli_common.invoke_context import InvokeContext
from samcli.commands.local.lib.debug_context import DebugContext
from samcli.local.lambdafn.exceptions import FunctionNotFound
from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException

Expand All @@ -36,38 +35,39 @@
@cli_framework_options
@click.argument('function_identifier', required=False)
@pass_context
def cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, debugger_path,
docker_volume_basedir, docker_network, log_file, skip_pull_image, profile):
def cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, docker_volume_basedir,
docker_network, log_file, skip_pull_image, profile):

# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing

do_cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, debugger_path,
docker_volume_basedir, docker_network, log_file, skip_pull_image, profile) # pragma: no cover
do_cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, docker_volume_basedir,
docker_network, log_file, skip_pull_image, profile) # pragma: no cover


def do_cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, # pylint: disable=R0914
debugger_path, docker_volume_basedir, docker_network, log_file, skip_pull_image, profile):
def do_cli(ctx, function_identifier, template, event, env_vars, debug_port, debug_args, docker_volume_basedir,
docker_network, log_file, skip_pull_image, profile):
"""
Implementation of the ``cli`` method, just separated out for unit testing purposes
"""

LOG.debug("local invoke command is called")

event_data = _get_event(event)
debug_context = _get_debug_context(debug_port, debug_args, debugger_path)

# Pass all inputs to setup necessary context to invoke function locally.
# Handler exception raised by the processor for invalid args and print errors
try:

with InvokeContext(template_file=template,
function_identifier=function_identifier,
env_vars_file=env_vars,
debug_port=debug_port,
debug_args=debug_args,
docker_volume_basedir=docker_volume_basedir,
docker_network=docker_network,
log_file=log_file,
skip_pull_image=skip_pull_image,
aws_profile=profile,
debug_context=debug_context) as context:
aws_profile=profile) as context:

# Invoke the function
context.local_lambda_runner.invoke(context.function_name,
Expand Down Expand Up @@ -97,16 +97,3 @@ def _get_event(event_file_name):
# accidentally closing a standard stream
with click.open_file(event_file_name, 'r') as fp:
return fp.read()


def _get_debug_context(debug_port, debug_args, debugger_path):
"""
Returns a debug context from debug options; Separated out for unit testing.
:param int debug_port: Container debug port
:param string debug_args: Extra debug arguments for process
:param string debugger_path: Path to debugger on host
:return DebugContext:
"""
if not debug_port or debug_args or debugger_path:
return None
return DebugContext(debug_port=debug_port, debug_args=debug_args, debugger_path=debugger_path)
15 changes: 0 additions & 15 deletions samcli/commands/local/lib/debug_context.py

This file was deleted.

14 changes: 9 additions & 5 deletions samcli/commands/local/lib/local_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def __init__(self,
function_provider,
cwd,
env_vars_values=None,
aws_profile=None,
debug_context=None):
debug_port=None,
debug_args=None,
aws_profile=None
):
"""
Initializes the class
Expand All @@ -44,8 +46,9 @@ def __init__(self,
self.provider = function_provider
self.cwd = cwd
self.env_vars_values = env_vars_values or {}
self.debug_port = debug_port
self.debug_args = debug_args
self.aws_profile = aws_profile
self.debug_context = debug_context

def invoke(self, function_name, event, stdout=None, stderr=None):
"""
Expand Down Expand Up @@ -73,7 +76,8 @@ def invoke(self, function_name, event, stdout=None, stderr=None):
config = self._get_invoke_config(function)

# Invoke the function
self.local_runtime.invoke(config, event, debug_context=self.debug_context, stdout=stdout, stderr=stderr)
self.local_runtime.invoke(config, event, debug_port=self.debug_port, debug_args=self.debug_args,
stdout=stdout, stderr=stderr)

def is_debugging(self):
"""
Expand All @@ -85,7 +89,7 @@ def is_debugging(self):
True, if we are debugging the invoke ie. the Docker container will break into the debugger and wait for
attach
"""
return bool(self.debug_context)
return bool(self.debug_port)

def _get_invoke_config(self, function):
"""
Expand Down
29 changes: 7 additions & 22 deletions samcli/commands/local/start_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from samcli.cli.main import pass_context, common_options as cli_framework_options
from samcli.commands.local.cli_common.options import invoke_common_options
from samcli.commands.local.cli_common.invoke_context import InvokeContext
from samcli.commands.local.lib.debug_context import DebugContext
from samcli.commands.local.lib.exceptions import NoApisDefined
from samcli.commands.local.cli_common.user_exceptions import UserException
from samcli.commands.local.lib.local_api_service import LocalApiService
Expand Down Expand Up @@ -48,38 +47,37 @@ def cli(ctx,
host, port, static_dir,

# Common Options for Lambda Invoke
template, env_vars, debug_port, debug_args, debugger_path, docker_volume_basedir,
template, env_vars, debug_port, debug_args, docker_volume_basedir,
docker_network, log_file, skip_pull_image, profile
):
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing

do_cli(ctx, host, port, static_dir, template, env_vars, debug_port, debug_args, debugger_path,
docker_volume_basedir, docker_network, log_file, skip_pull_image, profile) # pragma: no cover
do_cli(ctx, host, port, static_dir, template, env_vars, debug_port, debug_args, docker_volume_basedir,
docker_network, log_file, skip_pull_image, profile) # pragma: no cover


def do_cli(ctx, host, port, static_dir, template, env_vars, debug_port, debug_args, # pylint: disable=R0914
debugger_path, docker_volume_basedir, docker_network, log_file, skip_pull_image, profile):
docker_volume_basedir, docker_network, log_file, skip_pull_image, profile):
"""
Implementation of the ``cli`` method, just separated out for unit testing purposes
"""

LOG.debug("local start-api command is called")

debug_context = _get_debug_context(debug_port, debug_args, debugger_path)

# Pass all inputs to setup necessary context to invoke function locally.
# Handler exception raised by the processor for invalid args and print errors

try:
with InvokeContext(template_file=template,
function_identifier=None, # Don't scope to one particular function
env_vars_file=env_vars,
debug_port=debug_port,
debug_args=debug_args,
docker_volume_basedir=docker_volume_basedir,
docker_network=docker_network,
log_file=log_file,
skip_pull_image=skip_pull_image,
aws_profile=profile,
debug_context=debug_context) as invoke_context:
aws_profile=profile) as invoke_context:

service = LocalApiService(lambda_invoke_context=invoke_context,
port=port,
Expand All @@ -91,16 +89,3 @@ def do_cli(ctx, host, port, static_dir, template, env_vars, debug_port, debug_ar
raise UserException("Template does not have any APIs connected to Lambda functions")
except InvalidSamDocumentException as ex:
raise UserException(str(ex))


def _get_debug_context(debug_port, debug_args, debugger_path):
"""
Returns a debug context from debug options; Separated out for unit testing.
:param int debug_port: Container debug port
:param string debug_args: Extra debug arguments for process
:param string debugger_path: Path to debugger on host
:return DebugContext:
"""
if not debug_port or debug_args or debugger_path:
return None
return DebugContext(debug_port=debug_port, debug_args=debug_args, debugger_path=debugger_path)
13 changes: 2 additions & 11 deletions samcli/local/docker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def __init__(self,
exposed_ports=None,
entrypoint=None,
env_vars=None,
docker_client=None,
container_opts=None,
additional_volumes=None):
docker_client=None):
"""
Initializes the class with given configuration. This does not automatically create or run the container.
Expand All @@ -59,8 +57,6 @@ def __init__(self,
self._env_vars = env_vars
self._memory_limit_mb = memory_limit_mb
self._network_id = None
self._container_opts = container_opts
self._additional_volumes = additional_volumes

# Use the given Docker client or create new one
self.docker_client = docker_client or docker.from_env()
Expand Down Expand Up @@ -98,12 +94,6 @@ def create(self):
"tty": False
}

if self._container_opts:
kwargs.update(self._container_opts)

if self._additional_volumes:
kwargs["volumes"].update(self._additional_volumes)

if self._env_vars:
kwargs["environment"] = self._env_vars

Expand All @@ -130,6 +120,7 @@ def delete(self):
"""
Removes a container that was created earlier.
"""

if not self.is_created():
LOG.debug("Container was not created. Skipping deletion")
return
Expand Down
Loading

0 comments on commit 026a747

Please sign in to comment.