tox-dev / tox-docker

A tox plugin to run one or more Docker containers during tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support login to Docker Hub, to avoid throttling

neil-greenwood opened this issue · comments

We're seeing intermittent failures when using tox-docker 2.0.0:

2021-02-03 10:50:52 GMT+00:00 - Traceback (most recent call last):
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 268, in _raise_for_status
2021-02-03 10:50:52 GMT+00:00 - response.raise_for_status()
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 943, in raise_for_status
2021-02-03 10:50:52 GMT+00:00 - raise HTTPError(http_error_msg, response=self)
2021-02-03 10:50:52 GMT+00:00 - requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://localhost/v1.32/images/amazon/dynamodb-local:latest/json
2021-02-03 10:50:52 GMT+00:00 -
2021-02-03 10:50:52 GMT+00:00 - During handling of the above exception, another exception occurred:
2021-02-03 10:50:52 GMT+00:00 -
2021-02-03 10:50:52 GMT+00:00 - Traceback (most recent call last):
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/tox_docker/__init__.py", line 256, in tox_runtest_pre
2021-02-03 10:50:52 GMT+00:00 - docker.images.get(image)
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/models/images.py", line 316, in get
2021-02-03 10:50:52 GMT+00:00 - return self.prepare_model(self.client.api.inspect_image(name))
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/utils/decorators.py", line 19, in wrapped
2021-02-03 10:50:52 GMT+00:00 - return f(self, resource_id, *args, **kwargs)
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/api/image.py", line 254, in inspect_image
2021-02-03 10:50:52 GMT+00:00 - self._get(self._url("/images/{0}/json", image)), True
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 274, in _result
2021-02-03 10:50:52 GMT+00:00 - self._raise_for_status(response)
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/api/client.py", line 270, in _raise_for_status
2021-02-03 10:50:52 GMT+00:00 - raise create_api_error_from_http_exception(e)
2021-02-03 10:50:52 GMT+00:00 - File "/usr/local/lib/python3.6/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
2021-02-03 10:50:52 GMT+00:00 - raise cls(e, response=response, explanation=explanation)
2021-02-03 10:50:52 GMT+00:00 - docker.errors.ImageNotFound: 404 Client Error for http+docker://localhost/v1.32/images/amazon/dynamodb-local:latest/json: Not Found ("no such image: amazon/dynamodb-local:latest: No such image: amazon/dynamodb-local:latest")

I guess these are caused by the throttling of unauthenticated pulls from hub.docker.com

Maybe something like this (and storing the appropriate parameters):

$ git diff
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
modified: tox_docker/__init__.py
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ tox_docker/__init__.py:260 @ def tox_runtest_pre(venv):  # noqa: C901
         except ImageNotFound:
             action.setactivity("docker", f"pull {image!r} (from {container_name!r})")
             with action:
+                if 'username' in envconfig.docker:
+                    docker.login(envconfig.docker['username'], envconfig.docker['password'])
                 docker.images.pull(name, tag=tag or None)

     envconfig._docker_containers = {}

I think that leaves the password in cleartext though, which I don't like.

Wouldn't it be better to rely on the existing ~/.docker/config.json generated by docker login?