aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
764 stars 220 forks source link

Informative 'Docker is unreachable' error only shown in some contexts #1190

Open OscarVanL opened 5 years ago

OscarVanL commented 5 years ago

Describe the bug

I tried running my Lambda function locally this morning and was greeted with this cryptic error.

2019-08-30 16:23:41 Starting Build inside a container
2019-08-30 16:23:46 Building resource 'Function'
Traceback (most recent call last):
  File "runpy.py", line 193, in _run_module_as_main
  File "runpy.py", line 85, in _run_code
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
    cli(prog_name="sam")
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 94, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 65, in wrapped
    return_value = func(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 105, in cli
    skip_pull_image, parameter_overrides, mode)  # pragma: no cover
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 150, in do_cli
    artifacts = builder.build()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 108, in build
    lambda_function.runtime)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 199, in _build_function
    runtime)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\build\app_builder.py", line 234, in _build_function_on_container
    if not self._container_manager.is_docker_reachable:
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\manager.py", line 50, in is_docker_reachable
    self.docker_client.ping()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\client.py", line 187, in ping
    return self.api.ping(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 230, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\urllib3\connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\urllib3\connectionpool.py", line 355, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "http\client.py", line 1239, in request
  File "http\client.py", line 1285, in _send_request
  File "http\client.py", line 1234, in endheaders
  File "http\client.py", line 1026, in _send_output
  File "http\client.py", line 964, in send
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipeconn.py", line 32, in connect
    sock.connect(self.npipe_path)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 22, in wrapped
    return f(self, *args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 50, in connect
    win32pipe.WaitNamedPipe(address, self._timeout)
pywintypes.error: (2, 'WaitNamedPipe', 'The system cannot find the file specified.')

This turned out to be because Docker Desktop was not running and I have the Build function inside a container checkbox set.

I started Docker Desktop, and continually tried running the function. Interestingly, only if Docker is in the process of starting, do you get an informative error message:

2019-08-30 16:26:39 Starting Build inside a container
2019-08-30 16:26:39 Building resource 'Function'

Build Failed
Error: Docker is unreachable. Docker needs to be running to build inside a container.

To reproduce

  1. Start a local Lambda function with Docker Desktop closed and observe the ugly error
  2. Start Docker Desktop and repeatedly run the local lambda function
  3. After a while you will see the informative error.

Expected behavior

The informative error is shown all the time, it would have helped me this morning :)

Screenshots

N/A

Your Environment

Additional context

Docker Desktop Version: 2.1.0.1

OscarVanL commented 5 years ago

I was thinking of adding some kind of check at

if (samOptions.buildInContainer) {
                commandLine.withParameters("--use-container")
            }

in LambdaBuilder.kt and if that check doesn't pass, then give an informative error message.

It would need to be checked just before SAM build to ensure the user hasn't closed it (since checking the box).

(I also need to check if Docker Desktop must be open when you right click template.yaml and deploy serverless application inside a docker container, and if so, does this case also get handled by an addition here).

OscarVanL commented 5 years ago

A way of verifying if Docker is running is the CLI command docker info, which returns exit code 1 if not running, or exit code 0 if running/working.

This would, however, require that the user has docker in their system PATH. Although this may be a prerequisite that AWS SAM CLI already requires, so perhaps this isn't an issue. I should investigate if SAM works if docker is installed but not in the system PATH.

abrooksv commented 5 years ago

This should probably be fixed at the SAM CLI layer by providing better error messages.

OscarVanL commented 5 years ago

Sure, I'll make an issue there instead.

justinmk3 commented 4 years ago