docker / docker/docker-py

images.build is swallowing the error message from docker build

Open
#2,492 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

Expected:
Full docker build error log should be captured in BuildError.

Problematic source code in the library:
https://github.com/docker/docker-py/blob/1fc62e6a32c2d3257d5d033fcf924fabb16190ac/docker/models/images.py#L287
AND
https://github.com/docker/docker-py/blob/1fc62e6a32c2d3257d5d033fcf924fabb16190ac/docker/models/images.py#L298

I believe this is the problem - last_event = chunk.

Issue:
This is the error I currently get with image.build from this library:

docker_client_from_env.images.build failed on BuildError: The command '/bin/sh -c pip install --no-cache-dir --upgrade --extra-index-url ${EXTRA_INDEX_URL} /src/' returned a non-zero code: 1

However if I run the docker build directly I get the full error:

    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-bvyfl5jd/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-bvyfl5jd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-req-build-bvyfl5jd/
    Complete output (23 lines):
    Couldn't find index page for 'some_package' (maybe misspelled?)
    No local packages or working download links found for some_package>=0.25131.0
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-bvyfl5jd/setup.py", line 49, in <module>
        "PyHamcrest>=1.8.5",
      File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 144, in setup
        _install_setup_requires(attrs)
      File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 719, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
        replace_conflicting=replace_conflicting
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1065, in best_match
        return self.obtain(req, installer)
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1077, in obtain
        return installer(requirement)
      File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 786, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/local/lib/python3.7/site-packages/setuptools/command/easy_install.py", line 673, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('some_package>=0.25431.0')
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install --no-cache-dir --upgrade --extra-index-url ${EXTRA_INDEX_URL} /src/ &&     apt-get remove --purge -y ${BUILD_PACKAGES} &&     apt-get autoremove -y &&     rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in docker/models/images.py at the referenced lines 287 and 298, focusing on how image.build processes Docker build output and assigns the last event. Reproduce the failing build behavior and verify that BuildError captures the full docker build error log rather than only the final command error.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.