From ca84700f5ed97265aacd7342c31fba08a9460b26 Mon Sep 17 00:00:00 2001 From: Aaron Virshup Date: Wed, 21 Feb 2018 17:29:15 -0800 Subject: [PATCH 1/2] Add test for issue #46 --- test/data/buildfailure.yml | 5 +++++ test/test_errors.py | 1 + 2 files changed, 6 insertions(+) create mode 100644 test/data/buildfailure.yml diff --git a/test/data/buildfailure.yml b/test/data/buildfailure.yml new file mode 100644 index 0000000..d92864e --- /dev/null +++ b/test/data/buildfailure.yml @@ -0,0 +1,5 @@ +target: + description: Build commands fail + FROM: alpine + build: | + RUN exit 1 \ No newline at end of file diff --git a/test/test_errors.py b/test/test_errors.py index aabbee0..1622dc1 100644 --- a/test/test_errors.py +++ b/test/test_errors.py @@ -15,6 +15,7 @@ 'data/invalid_requires.yml': errors.InvalidRequiresList, 'data/invalid_yaml.yml': errors.ParsingFailure, 'data/multi_ignore.yml': errors.MultipleIgnoreError, + 'data/buildfailure.yml': errors.BuildError } From 8086093c523651ed8115c1eb14a36a1651617aac Mon Sep 17 00:00:00 2001 From: Aaron Virshup Date: Wed, 21 Feb 2018 17:53:37 -0800 Subject: [PATCH 2/2] Use native strs for build failure error messages --- codeship-steps.yml | 6 +++++- dockermake/errors.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/codeship-steps.yml b/codeship-steps.yml index 46c2259..6128ad9 100644 --- a/codeship-steps.yml +++ b/codeship-steps.yml @@ -1,3 +1,7 @@ +- name: clean-build + service: avirshup/docker-make + command: sh -c "rm -f /opt/distfiles/*" + - name: build-pkg service: avirshup/docker-make command: sh -c 'cp -v /opt/DockerMake/dist/DockerMake-*.tar.gz /opt/distfiles/' @@ -9,7 +13,7 @@ - testenv-python3.5 - testenv-python3.6 steps: - - command: sh -c "pip install /opt/distfiles/DockerMake-*.tar.gz && py.test" + - command: sh -c "pip install /opt/distfiles/DockerMake-*.tar.gz && py.test -v" - name: deploy-dockerhub type: push diff --git a/dockermake/errors.py b/dockermake/errors.py index 6d9d2e3..9c44c8b 100644 --- a/dockermake/errors.py +++ b/dockermake/errors.py @@ -13,9 +13,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from io import StringIO +import io import pprint from termcolor import cprint +from future.utils import PY2 class UserException(Exception): """ @@ -84,12 +85,14 @@ class BuildError(Exception): def __init__(self, dockerfile, item, build_args): with open('dockerfile.fail', 'w') as dff: print(dockerfile, file=dff) - with StringIO() as stream: + + buffer_class = io.BytesIO if PY2 else io.StringIO + with buffer_class() as stream: cprint('Docker build failure', 'red', attrs=['bold'], file=stream) - print(u'\n -------- Docker daemon output --------', file=stream) + print('\n -------- Docker daemon output --------', file=stream) pprint.pprint(item, stream, indent=4) - print(u' -------- Arguments to client.build --------', file=stream) + print(' -------- Arguments to client.build --------', file=stream) pprint.pprint(build_args, stream, indent=4) - print(u'This dockerfile was written to dockerfile.fail', file=stream) + print('This dockerfile was written to dockerfile.fail', file=stream) stream.seek(0) super(BuildError, self).__init__(stream.read())