dockerfile argument in images.build() is defaulting to HTTP, not file source
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Summary
When trying to build a Dockerfile from local file system while running in pytest, images.build() fails for HTTP 404. Issue is not present in 3.0.1
System Info
- Python 3.6.3
- pytest-3.4.1
- docker-py: 3.1.0
- docker: 17.12.0-ce
- OS: macOs 10.13.3
Code snippet works under 3.0.1 but not 3.1.0
Reproduction
Code
run as a pytest test.
from os import path
import docker
HERE = path.abspath(path.dirname(__file__))
ROOT = path.dirname(HERE)
CLIENT = docker.from_env(timeout=1)
def test_build_image():
image, log = CLIENT.images.build(
buildargs={'PROJECT_SOURCE': '/opt/PROJECT_NAME/'},
dockerfile=path.join(HERE, 'Dockerfile'),
path=ROOT,
nocache=True
)
Traceback
pytest output:
self = <docker.api.client.APIClient object at 0x10d34de10>, response = <Response [500]>
def _raise_for_status(self, response):
"""Raises stored :class:`APIError`, if one occurred."""
try:
> response.raise_for_status()
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:223:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Response [500]>
def raise_for_status(self):
"""Raises stored :class:`HTTPError`, if one occurred."""
http_error_msg = ''
if isinstance(self.reason, bytes):
# We attempt to decode utf-8 first because some servers
# choose to localize their reason strings. If the string
# isn't utf-8, we fall back to iso-8859-1 for all other
# encodings. (See PR #3538)
try:
reason = self.reason.decode('utf-8')
except UnicodeDecodeError:
reason = self.reason.decode('iso-8859-1')
else:
reason = self.reason
if 400 <= self.status_code < 500:
http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)
elif 500 <= self.status_code < 600:
http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)
if http_error_msg:
> raise HTTPError(http_error_msg, response=self)
E requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localunixsocket/v1.35/build?q=False&nocache=True&rm=False&forcerm=False&pull=False&dockerfile=%2FUsers%2Fjpurcell%2FCrowdstrike%2Fsensor%2FTest%2Fcookiecutters%2FDEMO_FlaskCookiecutter%2Ftests%2FDockerfile&buildargs=%7B%22PROJECT_SOURCE%22%3A+%22%2Fopt%2Fcrowdstrike%2FDEMO_FlaskCookiecutter%2Fsource%2F%22%7D
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/requests/models.py:935: HTTPError
During handling of the above exception, another exception occurred:
def test_build_image():
image, log = CLIENT.images.build(
buildargs={'PROJECT_SOURCE': '/opt/crowdstrike/DEMO_FlaskCookiecutter/source/'},
dockerfile=path.join(HERE, 'Dockerfile'),
path=HERE,
> nocache=True
)
tests/test_integration.py:32:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/models/images.py:187: in build
for chunk in internal_stream:
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/utils/json_stream.py:66: in split_buffer
for data in stream_as_text(stream):
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/utils/json_stream.py:22: in stream_as_text
for data in stream:
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:314: in _stream_helper
yield self._result(response, json=decode)
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:229: in _result
self._raise_for_status(response)
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:225: in _raise_for_status
raise create_api_error_from_http_exception(e)
tests/helpers.py:76: in start_docker
nocache=True,
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/models/images.py:187: in build
for chunk in internal_stream:
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/utils/json_stream.py:66: in split_buffer
for data in stream_as_text(stream):
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/utils/json_stream.py:22: in stream_as_text
for data in stream:
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:314: in _stream_helper
yield self._result(response, json=decode)
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:229: in _result
self._raise_for_status(response)
venv_DEMO_FlaskCookiecutter/lib/python3.6/site-packages/docker/api/client.py:225: in _raise_for_status
raise create_api_error_from_http_exception(e)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Code works OK in REPL, but not in pytest. Works in both on 3.0.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the images.build() entry point shown in docker/models/images.py and compare the pytest call in tests/test_integration.py with the REPL behavior; inspect the request path in the traceback and the related call in tests/helpers.py. Reproduce with the listed Docker and Python versions, then verify that building a local Dockerfile under pytest uses the file source correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100