mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nlp.git
synced 2024-12-26 21:14:18 +00:00
Update for unprivileged usage 2
This commit is contained in:
parent
737a1db496
commit
c5ce5b1c87
@ -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 \
|
||||
|
25
wrapper/nlp
25
wrapper/nlp
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user