metaparticle-io / package

Metaparticle/Package: Language Fluent Containerization and Deployment in Java, .NET and Javascript (and more coming soon)
https://metaparticle.io
MIT License
493 stars 55 forks source link

APIClient runs in docker and crashes there #116

Closed huitseeker closed 6 years ago

huitseeker commented 6 years ago

When rebuilding any images in the python/examples directory, the docker builder's initialization includes a call to APIClient(version='auto'), which crashes when run in docker (for lack of a /var/run/docker.sock to find).

This was probably introduced around https://github.com/metaparticle-io/package/commit/686bc97b31b60fa3afeae1bb73d2506e4c651650

The error message observed then is:

web-bdf65ff5-zd9hw:web-0     'Error while fetching server API version: {0}'.format(e)
web-bdf65ff5-zd9hw:web-0 docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
web-bdf65ff5-l9ltn:web-0 Traceback (most recent call last):
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
web-bdf65ff5-l9ltn:web-0     chunked=chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
web-bdf65ff5-l9ltn:web-0     conn.request(method, url, **httplib_request_kw)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
web-bdf65ff5-l9ltn:web-0     self._send_request(method, url, body, headers, encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
web-bdf65ff5-l9ltn:web-0     self.endheaders(body, encode_chunked=encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
web-bdf65ff5-l9ltn:web-0     self._send_output(message_body, encode_chunked=encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
web-bdf65ff5-l9ltn:web-0     self.send(msg)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 964, in send
web-bdf65ff5-l9ltn:web-0     self.connect()
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/transport/unixconn.py", line 46, in connect
web-bdf65ff5-l9ltn:web-0     sock.connect(self.unix_socket)
web-bdf65ff5-l9ltn:web-0 FileNotFoundError: [Errno 2] No such file or directory
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 During handling of the above exception, another exception occurred:
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 Traceback (most recent call last):
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
web-bdf65ff5-l9ltn:web-0     timeout=timeout
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
web-bdf65ff5-l9ltn:web-0     _stacktrace=sys.exc_info()[2])
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
web-bdf65ff5-l9ltn:web-0     raise six.reraise(type(error), error, _stacktrace)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
web-bdf65ff5-l9ltn:web-0     raise value.with_traceback(tb)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
web-bdf65ff5-l9ltn:web-0     chunked=chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
web-bdf65ff5-l9ltn:web-0     conn.request(method, url, **httplib_request_kw)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
web-bdf65ff5-l9ltn:web-0     self._send_request(method, url, body, headers, encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
web-bdf65ff5-l9ltn:web-0     self.endheaders(body, encode_chunked=encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
web-bdf65ff5-l9ltn:web-0     self._send_output(message_body, encode_chunked=encode_chunked)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
web-bdf65ff5-l9ltn:web-0     self.send(msg)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/http/client.py", line 964, in send
web-bdf65ff5-l9ltn:web-0     self.connect()
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/transport/unixconn.py", line 46, in connect
web-bdf65ff5-l9ltn:web-0     sock.connect(self.unix_socket)
web-bdf65ff5-l9ltn:web-0 urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 During handling of the above exception, another exception occurred:
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 Traceback (most recent call last):
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 168, in _retrieve_server_version
web-bdf65ff5-l9ltn:web-0     return self.version(api_version=False)["ApiVersion"]
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/api/daemon.py", line 177, in version
web-bdf65ff5-l9ltn:web-0     return self._result(self._get(url), json=True)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/utils/decorators.py", line 46, in inner
web-bdf65ff5-l9ltn:web-0     return f(self, *args, **kwargs)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 191, in _get
web-bdf65ff5-l9ltn:web-0     return self.get(url, **self._set_request_timeout(kwargs))
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 521, in get
web-bdf65ff5-l9ltn:web-0     return self.request('GET', url, **kwargs)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
web-bdf65ff5-l9ltn:web-0     resp = self.send(prep, **send_kwargs)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
web-bdf65ff5-l9ltn:web-0     r = adapter.send(request, **kwargs)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
web-bdf65ff5-l9ltn:web-0     raise ConnectionError(err, request=request)
web-bdf65ff5-l9ltn:web-0 requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 During handling of the above exception, another exception occurred:
web-bdf65ff5-l9ltn:web-0 
web-bdf65ff5-l9ltn:web-0 Traceback (most recent call last):
web-bdf65ff5-l9ltn:web-0   File "/app/web.py", line 28, in <module>
web-bdf65ff5-l9ltn:web-0     runtime={'ports': [8080], 'executor': 'metaparticle', 'replicas': 3, 'public': True}
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/metaparticle_pkg/containerize.py", line 58, in __init__
web-bdf65ff5-l9ltn:web-0     self.builder = builder.select(self.package.builder)
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/metaparticle_pkg/builder/__init__.py", line 6, in select
web-bdf65ff5-l9ltn:web-0     return DockerBuilder()
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/metaparticle_pkg/builder/docker_builder.py", line 11, in __init__
web-bdf65ff5-l9ltn:web-0     self.docker_client = APIClient(version='auto')
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 149, in __init__
web-bdf65ff5-l9ltn:web-0     self._version = self._retrieve_server_version()
web-bdf65ff5-l9ltn:web-0   File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 176, in _retrieve_server_version
web-bdf65ff5-l9ltn:web-0     'Error while fetching server API version: {0}'.format(e)
web-bdf65ff5-l9ltn:web-0 docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Steps to reproduce:

huitseeker commented 6 years ago

A solution is probably to move the initialization of builder and runner in containerize to lazy properties (since we don't know if we're gonna need them at initialization of the Containerize class)

brendandburns commented 6 years ago

I'll try to repro this (or if you have a good handle on the issue, I'd love a PR)

THanks!

brendandburns commented 6 years ago

I created https://github.com/metaparticle-io/package/pull/119

Which should address this....