Skip to content

Commit

Permalink
Set default docker user to os.getuid() #922
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Mar 17, 2018
1 parent 9c2b548 commit 70fb65f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/sos/docker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,16 @@ def run(self, image, script='', interpreter='', args='', suffix='.sh', **kwargs)
volumes_from_opt = ''
if 'volumes_from' in kwargs:
if isinstance(kwargs['volumes_from'], str):
volumes_from_opt = '--volumes_from={}'.format(kwargs['volumes_from'])
volumes_from_opt = f'--volumes_from={kwargs["volumes_from"]}'
elif isinstance(kwargs['volumes_from'], list):
volumes_from_opt = ' '.join('--volumes_from={}'.format(x) for x in kwargs['volumes_from'])
volumes_from_opt = ' '.join(f'--volumes_from={x}' for x in kwargs['volumes_from'])
else:
raise RuntimeError('Option volumes_from only accept a string or list of string: {} specified'.format(kwargs['volumes_from']))
# we also need to mount the script
cmd_opt = ''
if script and interpreter:
volumes_opt += ' -v {}:{}'.format(shlex.quote(os.path.join(tempdir, tempscript)), '/var/lib/sos/{}'.format(tempscript))
cmd_opt = interpolate('{} {}'.format(interpreter, args),
cmd_opt = interpolate(f'{interpreter} {args}',
{'filename': sos_targets(f'/var/lib/sos/{tempscript}')})
#
working_dir_opt = '-w={}'.format(shlex.quote(os.path.abspath(os.getcwd())))
Expand All @@ -232,11 +232,11 @@ def run(self, image, script='', interpreter='', args='', suffix='.sh', **kwargs)
env_opt = ''
if 'environment' in kwargs:
if isinstance(kwargs['environment'], dict):
env_opt = ' '.join('-e {}={}'.format(x,y) for x,y in kwargs['environment'].items())
env_opt = ' '.join(f'-e {x}={y}' for x,y in kwargs['environment'].items())
elif isinstance(kwargs['environment'], list):
env_opt = ' '.join('-e {}'.format(x) for x in kwargs['environment'])
env_opt = ' '.join(f'-e {x}' for x in kwargs['environment'])
elif isinstance(kwargs['environment'], str):
env_opt = '-e {}'.format(kwargs['environment'])
env_opt = f'-e {kwargs["environment"]}'
else:
raise RuntimeError('Invalid value for option environment (str, list, or dict is allowd, {} provided)'.format(kwargs['environment']))
#
Expand All @@ -251,7 +251,7 @@ def run(self, image, script='', interpreter='', args='', suffix='.sh', **kwargs)
#
name_opt = ''
if 'name' in kwargs:
name_opt = '--name={}'.format(kwargs['name'])
name_opt = f'--name={kwargs["name"]}'
#
stdin_opt = ''
if 'stdin_open' in kwargs and kwargs['stdin_optn']:
Expand All @@ -261,9 +261,11 @@ def run(self, image, script='', interpreter='', args='', suffix='.sh', **kwargs)
if 'tty' in kwargs and not kwargs['tty']:
tty_opt = ''
#
user_opt = ''
if 'user' in kwargs:
user_opt = '-u {}'.format(kwargs['user'])
user_opt = f'-u {kwargs["user"]}'
else:
# Tocket #922
user_opt = f'-u {os.getuid()}'
#
extra_opt = ''
if 'extra_args' in kwargs:
Expand Down Expand Up @@ -309,5 +311,5 @@ def run(self, image, script='', interpreter='', args='', suffix='.sh', **kwargs)
else:
raise RuntimeError('Script killed by docker, probably because of lack of RAM (available RAM={:.1f}GB, exitcode=137). '.format(self.tot_mem/1024/1024) + msg)
else:
raise RuntimeError('Executing script in docker returns an error (exitcode={}). '.format(ret) + msg)
raise RuntimeError(f'Executing script in docker returns an error (exitcode={res}). {msg}')
return 0

0 comments on commit 70fb65f

Please sign in to comment.