Skip to content

Commit ba423bc

Browse files
committed
udpdate: add error trace for RUN_bash_script
1 parent 775d329 commit ba423bc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pydocker.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class DockerFile(pydocker.DockerFile):
7272
v1.0.4 Fri May 3 14:18:31 UTC 2019 jen
7373
- fix regex validation of img name
7474
75+
v1.0.5 Sat Jun 15 11:21:02 UTC 2019 jen
76+
- add error trace for RUN_bash_script
77+
7578
7679
--------------------------------------------------------------------------------
7780
contributors:
@@ -182,7 +185,20 @@ def COPY(self, dst_path, content, chmod=None):
182185
self.add_new_file(dst_path, content, chmod=chmod)
183186

184187
def RUN_bash_script(self, dst_path, content, keep_file=False):
185-
content = '#!/usr/bin/env bash\nset -o xtrace\n' + content
188+
# https://stackoverflow.com/questions/22009364/is-there-a-try-catch-command-in-bash
189+
# https://unix.stackexchange.com/questions/462156/how-do-i-find-the-line-number-in-bash-when-an-error-occured
190+
content = '''
191+
#!/usr/bin/env bash
192+
set -e -o xtrace
193+
194+
function _failure() {
195+
echo -e "\\r\\nERROR: bash script [ %(script_name)s ] failed at line $1: \\"$2\\""
196+
}
197+
trap '_failure ${LINENO} "$BASH_COMMAND"' ERR
198+
199+
# ############################################################################ #
200+
'''.strip() % {'script_name': dst_path} + '\n\n'+ content
201+
186202
self.COPY(dst_path, content, chmod='+x')
187203
self.RUN = dst_path
188204
if not keep_file:

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# https://test.pypi.org/project/pydocker
3434
# pip install --no-cache-dir -U -i https://test.pypi.org/pypi pydocker
3535
36-
# git tag -a v1.0.4 -m 'version 1.0.4'
36+
# git tag -a v1.0.5 -m 'version 1.0.5'
3737
3838
# ------------------------------------------------------------------------------
3939
rm -rf ./dist
@@ -42,7 +42,7 @@
4242
python3.4 setup.py sdist # EGG
4343
python3.4 -m twine upload dist/* -r pypi
4444
45-
# pip install --no-cache-dir -U pydocker==1.0.4
45+
# pip install --no-cache-dir -U pydocker==1.0.5
4646
# ls -lah /usr/local/lib/python2.7/dist-packages | grep pydocker
4747
4848
# ------------------------------------------------------------------------------
@@ -58,7 +58,7 @@
5858

5959
setup(
6060
name='pydocker',
61-
version='1.0.4',
61+
version='1.0.5',
6262

6363
description='Easy generator Dockerfile for humans.',
6464
long_description=long_description,
@@ -73,7 +73,7 @@
7373
maintainer_email='[email protected]',
7474

7575
platforms=['any', ],
76-
download_url='https://github.com/jen-soft/pydocker/archive/v1.0.4.zip',
76+
download_url='https://github.com/jen-soft/pydocker/archive/v1.0.5.zip',
7777

7878
# packages=['pydocker', ],
7979
py_modules=['pydocker', ],

0 commit comments

Comments
 (0)