Skip to content

Commit

Permalink
Merge pull request #50 from avirshup/build_error_unicode
Browse files Browse the repository at this point in the history
Fix error when formatting build failure messages in py2.7
  • Loading branch information
avirshup authored Feb 22, 2018
2 parents 951ee35 + 8086093 commit fef0403
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion codeship-steps.yml
Original file line number Diff line number Diff line change
@@ -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/'
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions dockermake/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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())
5 changes: 5 additions & 0 deletions test/data/buildfailure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target:
description: Build commands fail
FROM: alpine
build: |
RUN exit 1
1 change: 1 addition & 0 deletions test/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down

0 comments on commit fef0403

Please sign in to comment.