Update for unprivileged usage 2

This commit is contained in:
Patrick Jentsch 2019-06-03 13:32:37 +02:00
parent 737a1db496
commit c5ce5b1c87
2 changed files with 17 additions and 9 deletions

View File

@ -44,6 +44,7 @@ mkdir -p /<mydatalocation>/files_for_nlp /<mydatalocation>/files_from_nlp
docker run \
--rm \
-it \
-u $(id -u $USER):$(id -g $USER) \
-v /<mydatalocation>/files_for_nlp:/input \
-v /<mydatalocation>/files_from_nlp:/output \
sfb1288inf/nlp:latest \

View File

@ -2,9 +2,14 @@
# coding=utf-8
import argparse
import os
import subprocess
container_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/nlp:latest'
container_input_dir = '/input'
container_output_dir = '/output'
uid = str(os.getuid())
gid = str(os.getgid())
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
@ -17,16 +22,18 @@ parser.add_argument(
dest='output_dir',
required=True
)
dirs, args = parser.parse_known_args()
args, remaining_args = parser.parse_known_args()
cmd = ['docker', 'run', '--rm', '-it']
if dirs.input_dir is not None:
cmd += ['-v', dirs.input_dir + ':/input']
args += ['-i', '/input']
if dirs.output_dir is not None:
cmd += ['-v', dirs.output_dir + ':/output']
args += ['-o', '/output']
cmd = ['docker', 'run', '--rm', '-it', '-u', uid + ':' + gid]
if args.input_dir is not None:
host_input_dir = os.path.abspath(args.input_dir)
cmd += ['-v', host_input_dir + ':' + container_input_dir]
remaining_args += ['-i', '/input']
if args.output_dir is not None:
host_output_dir = os.path.abspath(args.output_dir)
cmd += ['-v', host_output_dir + ':' + container_output_dir]
remaining_args += ['-o', '/output']
cmd.append(container_image)
cmd += args
cmd += remaining_args
subprocess.run(cmd)